? Cynthiune.app ? cynthiune-fix-alsa.diff ? obj ? Bundles/ALSA/ALSA.output ? Bundles/ALSA/obj ? Bundles/AO/AO.output ? Bundles/AO/obj ? Bundles/ASFTags/ASFTags.tags ? Bundles/ASFTags/obj ? Bundles/AudioFile/AudioFile.format ? Bundles/AudioFile/obj ? Bundles/Esound/Esound.output ? Bundles/Esound/obj ? Bundles/FLAC/FLAC.format ? Bundles/FLAC/obj ? Bundles/ID3Tag/ID3Tag.tags ? Bundles/ID3Tag/obj ? Bundles/MP3/MP3.format ? Bundles/MP3/obj ? Bundles/Mod/Mod.format ? Bundles/Mod/obj ? Bundles/Musepack/Musepack.format ? Bundles/Musepack/obj ? Bundles/OSS/OSS.output ? Bundles/OSS/obj ? Bundles/Ogg/Ogg.format ? Bundles/Ogg/obj ? Bundles/Taglib/Taglib.tags ? Bundles/Taglib/obj ? Bundles/Timidity/Timidity.format ? Bundles/Timidity/obj ? Frameworks/Cynthiune/Cynthiune.framework ? Frameworks/Cynthiune/derived_src ? Frameworks/Cynthiune/obj Index: Bundles/ALSA/ALSA.m =================================================================== RCS file: /sources/gap/gap/user-apps/Cynthiune/Bundles/ALSA/ALSA.m,v retrieving revision 1.4 diff -u -r1.4 ALSA.m --- Bundles/ALSA/ALSA.m 23 May 2012 22:07:19 -0000 1.4 +++ Bundles/ALSA/ALSA.m 28 May 2012 19:28:35 -0000 @@ -77,6 +77,7 @@ rate = 0; stopRequested = NO; devLock = [NSLock new]; + en = SND_PCM_FORMAT_S16; } return self; @@ -85,30 +86,50 @@ - (BOOL) openDevice { int err; - BOOL result = NO; [devLock lock]; if ((err = snd_pcm_open (&pcm_handle, device, SND_PCM_STREAM_PLAYBACK, 0)) < 0) - NSRunAlertPanel (LOCALIZED (@"Error"), - LOCALIZED (@"Failed to open the ALSA device:\n%s"), - LOCALIZED (@"OK"), NULL, NULL, snd_strerror (err)); - else if ((err = snd_pcm_set_params (pcm_handle, en, - SND_PCM_ACCESS_RW_INTERLEAVED, - channels, rate, 1, 100000)) < 0) - NSRunAlertPanel (LOCALIZED (@"Error"), - LOCALIZED (@"Failed to set device parameters:\n%s"), - LOCALIZED (@"OK"), NULL, NULL, snd_strerror (err)); - else if ((err = snd_pcm_prepare (pcm_handle)) < 0) - NSRunAlertPanel (LOCALIZED (@"Error"), - LOCALIZED (@"Failed to prepare the ALSA device for " - @"playing:\n%s"), - LOCALIZED (@"OK"), NULL, NULL, snd_strerror (err)); - else - result = YES; + { + [devLock unlock]; + NSRunAlertPanel (LOCALIZED (@"Error"), + LOCALIZED (@"Failed to open the ALSA device:\n%s"), + LOCALIZED (@"OK"), NULL, NULL, snd_strerror (err)); + return NO; + } + + if ((err = snd_pcm_set_params (pcm_handle, en, + SND_PCM_ACCESS_RW_INTERLEAVED, + channels, rate, 1, 100000)) < 0) + { + /* we retry with resampling */ + + NSLog(@"Retry with fixed 44100 Hz rate and resampling"); + if ((err = snd_pcm_set_params (pcm_handle, en, + SND_PCM_ACCESS_RW_INTERLEAVED, + channels, 44100, 1, 100000)) < 0) + { + [devLock unlock]; + NSRunAlertPanel (LOCALIZED (@"Error"), + LOCALIZED (@"Failed to set device parameters:\n%s"), + LOCALIZED (@"OK"), NULL, NULL, snd_strerror (err)); + return NO; + } + } + + if ((err = snd_pcm_prepare (pcm_handle)) < 0) + { + [devLock unlock]; + NSRunAlertPanel (LOCALIZED (@"Error"), + LOCALIZED (@"Failed to prepare the ALSA device for " + @"playing:\n%s"), + LOCALIZED (@"OK"), NULL, NULL, snd_strerror (err)); + return NO; + } + [devLock unlock]; - return result; + return YES; } - (BOOL) prepareDeviceWithChannels: (unsigned int) numberOfChannels @@ -127,12 +148,18 @@ en = SND_PCM_FORMAT_S16; [devLock lock]; - if (pcm_handle) { - if ((err = snd_pcm_set_params(pcm_handle, en, - SND_PCM_ACCESS_RW_INTERLEAVED, - channels, rate, 1, 100000)) < 0) - NSLog(LOCALIZED (@"Failed to set device parameters:%s"), snd_strerror (err)); - } + if (pcm_handle) + { + if ((err = snd_pcm_set_params(pcm_handle, en, + SND_PCM_ACCESS_RW_INTERLEAVED, + channels, rate, 1, 100000)) < 0) + { + if ((err = snd_pcm_set_params(pcm_handle, en, + SND_PCM_ACCESS_RW_INTERLEAVED, + channels, 44100, 1, 100000)) < 0) + NSLog(LOCALIZED (@"Failed to set device parameters:%s"), snd_strerror (err)); + } + } [devLock unlock]; return YES; }