Pull to refresh

Design

Show first
Rating limit

Python: Using PyGame for real-time visualization of audio signals with a 44100 Hz sampling rate

PyGame is a popular library for developing 2D games in Python. The initial version of PyGame was presented by Pete Shinners in October 2000, and since then, the library has gradually gained popularity due to its ease of use, good documentation, and active community. Initially designed to work with early versions of Python (including Python 2), PyGame was based on the SDL 1 library. SDL is a cross-platform library in C that provides low-level access to audio devices, keyboard, mouse, and graphical functions via OpenGL, DirectX, etc.

The current versions 2.x fully support Python 3 (from 3.7 and above) and include a range of updates, such as improved OpenGL support, hardware acceleration, and the ability to work with vertical synchronization on monitors (VSync).

This article discusses an unconventional application of PyGame - the rapid display of graphs, for example, data streams with a 44100 Hz sampling rate from a sound card, which may be necessary for visualizing audio signals.

For such a task, the following functions and capabilities of PyGame are well-suited:

pygame.display.flip()  - quickly updates the screen content after changes 
                       #have been made.
#
Using pygame.time.Clock() - allows you to control FPS, 
                            which enables the system to request updates 
                            at up to 60 frames per second or more, which is 
                            important for displaying signals in real-time.
#
The new vsync flag (for example, passed to set_mode with 
                    the pygame.RESIZABLE or pygame.OPENGL parameter) 
                    can be used to synchronize screen updates with 
                    the display's vertical refresh rate.

The main loop (typical in PyGame):

running = True
while running:
    # Обработка событий
    # Генерация шума и обновление данных графика
    # Очистка экрана
    # Отрисовка сетки и графика
    # Подсчет и отображение FPS
    # Обновление экрана
    pygame.display.flip()
    clock.tick(FPS)

pygame.quit()

Read more info in my article

Tags:
Rating0
Comments1

Написал ебилд (это инсталлятор для Gentoo Linux) игры Gigalomania - клон известной Mega-Lo-Mania. Люблю эту игру, но печально видеть что оригинал выглядит значительно лучше. Пишу сюда чтобы сказать вам - вдруг вы или знакомый хотите потренироваться в создании визуального дизайна игр, улучшить портфолио на этом некоммерческом проекте - автор на странице игры написал что ждет вас:

Help wanted!

...

Graphics artists - Whilst most of the "placeholder" graphics have now been removed, there's still plenty of room for improvement, so please let me know.

Игра относительно простая, текстур там относительно немного. Механика классная.

а выглядит плохо
а выглядит плохо

Может знаете еще в какое комьюнити можно написать?

Сайт игры: https://gigalomania.sourceforge.net/

Спасибо.

Tags:
Total votes 1: ↑1 and ↓0+3
Comments0