Hello,
After a looong time completely busy, I finaly found the time to investigate, and start to see some light
After the recent changes, I finally can create a recording callback, and it seems to worrk as expected. If I understand correctly, the mistake was caused by a bad deviceID, and the trick was to only trust (and use) the value returned by
SDL_GetAudioDeviceName(aName.c_str(), SDL_TRUE, &wanted, &have, SDL_AUDIO_ALLOW_FREQUENCY_CHANGE | … ). Use the array number does not work, since it never match with the ID.
For the one interested, I implemented 3 classes:
- audiodevices : objects with audio devices properties, including callbakcs, and their own buffers
- audiomanager : create the list of audio devices as objects, including their own callback
- engine : SDL / OpenGL 3.x
In runtime : (debug is included, during the development phase), things work this way:
engine initializes the audiomanager. The audiomanager creates the list of all recordable audio devices.
A checkbox allows to diaplay the list, and once they are selected, every device is initialised once only (currently only recording the callback is created). Once this is done, one can select and start / stop recording.
Well, the next step is to check what contains the callback (stream of data if I’m not toowrong, and how to copy all of them in a file ( e.g. aac). Current track is to use ffmpeg (I got some working code, investigating).
Other current tracks : using a circular buffer (to help Windows protability).
The code is here :
- engine : Sources/src/Application/engine.cpp · master · Eric Bachard / miniDart · GitLab
- audiomanager: Sources/src/Audio/audiomanager.cpp · master · Eric Bachard / miniDart · GitLab
- audiodevice: Sources/src/Audio/audiodevice.cpp · master · Eric Bachard / miniDart · GitLab
- The implementation in main : Sources/src/Application/miniDart.cpp · master · Eric Bachard / miniDart · GitLab, around line 2034 to 2088
What helped me ?
- StackOverflow site : c - Recording microphone with SDL2 gets delayed by 2 seconds - Stack Overflow
- Lazy Foo tutorial : Lazy Foo' Productions - Audio Recording
- This code, (sorry, lost the source) : Sources/step3 · master · Eric Bachard / AudioRecord · GitLab
NEXT STEP : implement both recording and playback callbacks, and use them.
Feel free to suggest improvements, and thanks a lot to SDL2 : this API is black magic !