Hello,
I’m having trouble in getting SDL mixer working on my laptop, when calling “SDL_OpenAudioDevice” it gives this error “SNDCTL_DSP_GETFMTS: Invalid argument” and SDL_GetError() returns “Couldn’t get audio format list”
Not sure if the problem is related with my laptop having dual graphics, but here is aplay -l output
**** List of PLAYBACK Hardware Devices ****
card 0: PCH [HDA Intel PCH], device 0: ALC295 Analog [ALC295 Analog]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 3: HDMI 0 [HDMI 0]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 7: HDMI 1 [HDMI 1]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 8: HDMI 2 [HDMI 2]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 9: HDMI 3 [HDMI 3]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 10: HDMI 4 [HDMI 4]
Subdevices: 1/1
Subdevice #0: subdevice #0
also my code
#include <SDL2/SDL.h>
#include <math.h>
static double m_sineFreq = 1000;
static double m_sampleFreq = 44100;
static double m_samplesPerSine = (m_sampleFreq / m_sineFreq);
static uint32_t m_samplePos = 0;
void callback( void *userdata, Uint8 * stream, int len )
{
//memset( stream, 0, len );
for(int i = 0; i < len; ++i)
{
stream[i] = (sin(m_samplePos / m_samplesPerSine * M_PI * 2) + 1) * 127.5;
m_samplePos++;
}
printf("Buffer filled %d\n", m_samplePos);
}
int main()
{
if( SDL_Init( SDL_INIT_AUDIO ) != 0 )
{
printf("SDL_Init(): %s\n",SDL_GetError());
SDL_ClearError();
return 1;
}
int aud_dev = SDL_GetNumAudioDevices(0);
printf("Num of audio devices: %d\n", aud_dev);
SDL_AudioSpec specs = {}, available = {};
specs.freq = 44100;
specs.format = AUDIO_U8;
specs.channels = 1;
specs.samples = 2048;
specs.callback = callback;
specs.userdata = NULL;
constexpr int PLAYBACK_DEV = 0;
const int audio_dev_id = SDL_OpenAudioDevice( NULL, PLAYBACK_DEV, &specs, &available, SDL_AUDIO_ALLOW_FORMAT_CHANGE );
printf("Freq: %d\n"
"Format: %d\n"
"Channels: %d\n"
"Samples: %d\n",
available.freq,
available.format,
available.channels,
available.samples);
if( audio_dev_id == 0 )
{
printf("Error opening audio device: %s\n", SDL_GetError());
return 1;
}
SDL_PauseAudioDevice(audio_dev_id, 0);
//std::this_thread::sleep_for( std::chrono::seconds( 1 ) );
SDL_PauseAudioDevice(audio_dev_id, 1);
SDL_CloseAudioDevice(audio_dev_id);
}
Does any one have any idea?