-
What is the best way to access real time amplitude of microphone for displaying or control of a graphics object? For now, I'm trying to accomplish something relatively simple where I speak in the microphone and have an amplitude indicator (like what you see with a program like OBS studio). I have read through the examples of simple capture, simple playback, and simple duplex. I have been successful loading a wav file from disk with ma_decoder_read_pcm_frames using miniaudio with a simple C++ class. I use ma_decoder m_decoder and a std::vector m_FramesVec like so, ma_decoder_read_pcm_frames(&m_decoder, &m_FramesVec[0], n_samples, &framesread). I get n_samples from ma_decoder_get_length_in_pcm_frames and resize the std::vector before the read. I seem to struggle with the device and callback part of the minaudio API the most. Specifically, the pDevice->pUserData seems to be what I need to fully grasp. From what I have done so far, It's like I want to use the ma_encoder_write_pcm_frames to something like m_FramesVec where the encoder would write frames from the microphone frames grabbed by miniaudio rather than the ma_decoder reading those frames as I do from sounds loaded from disk, if that makes sense. I thought the simple duplex example would help me understand what was going on better, but I am confused as to how to utilize the pOutput or pInput without an encoder to write the frames to my own std::vector, for example. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
The simple_capture example is what you want. The playback and duplex examples won't help you, nor will The way it works is that you receive audio data from the microphone via the data callback. Once you have that data you can do whatever you want with it. To simplify it, set the format to |
Beta Was this translation helpful? Give feedback.
The simple_capture example is what you want. The playback and duplex examples won't help you, nor will
ma_decoder
. ThepUserData
member is just a way for you to associate an arbitrary pointer from your program with the device. That way you can access said pointer wherever you have access to ama_device
object, such as in the data callback. In the capture example it just happens to be that I designed it to use thepUserData
pointer with anma_encoder
object. You can assign it to whatever you want, or nothing at all - it just depends on how you want to design your program. For example, I could have instead declared thema_encoder
object globally in which case I wouldn't need to use thepUse…