84 |
return EXIT_FAILURE; |
return EXIT_FAILURE; |
85 |
} |
} |
86 |
|
|
87 |
|
int dir = 0; |
88 |
|
|
89 |
/* Set sample rate. If the exact rate is not supported */ |
/* Set sample rate. If the exact rate is not supported */ |
90 |
/* by the hardware, use nearest possible rate. */ |
/* by the hardware, use nearest possible rate. */ |
91 |
if((err = snd_pcm_hw_params_set_rate_near(pcm_handle, hwparams, samplerate, 0)) < 0) { |
#if ALSA_MAJOR > 0 |
92 |
|
if((err = snd_pcm_hw_params_set_rate_near(pcm_handle, hwparams, &samplerate, &dir)) < 0) { |
93 |
|
#else |
94 |
|
if((err = snd_pcm_hw_params_set_rate_near(pcm_handle, hwparams, samplerate, &dir)) < 0) { |
95 |
|
#endif |
96 |
fprintf(stderr, "Error setting sample rate. : %s\n", snd_strerror(err)); |
fprintf(stderr, "Error setting sample rate. : %s\n", snd_strerror(err)); |
97 |
return EXIT_FAILURE; |
return EXIT_FAILURE; |
98 |
} |
} |
103 |
} |
} |
104 |
|
|
105 |
/* Set number of periods. Periods used to be called fragments. */ |
/* Set number of periods. Periods used to be called fragments. */ |
106 |
if ((err = snd_pcm_hw_params_set_periods(pcm_handle, hwparams, numfragments, 0)) < 0) { |
if ((err = snd_pcm_hw_params_set_periods(pcm_handle, hwparams, numfragments, dir)) < 0) { |
107 |
fprintf(stderr, "Error setting number of periods. : %s\n", snd_strerror(err)); |
fprintf(stderr, "Error setting number of periods. : %s\n", snd_strerror(err)); |
108 |
return EXIT_FAILURE; |
return EXIT_FAILURE; |
109 |
} |
} |
176 |
snd_pcm_close(pcm_handle); |
snd_pcm_close(pcm_handle); |
177 |
return false; |
return false; |
178 |
} |
} |
179 |
if (snd_pcm_hw_params_test_rate(pcm_handle, hwparams, samplerate, 0) < 0) { |
int dir = 0; |
180 |
|
if (snd_pcm_hw_params_test_rate(pcm_handle, hwparams, samplerate, dir) < 0) { |
181 |
snd_pcm_close(pcm_handle); |
snd_pcm_close(pcm_handle); |
182 |
return false; |
return false; |
183 |
} |
} |
185 |
snd_pcm_close(pcm_handle); |
snd_pcm_close(pcm_handle); |
186 |
return false; |
return false; |
187 |
} |
} |
188 |
if (snd_pcm_hw_params_test_periods(pcm_handle, hwparams, numfragments, 0) < 0) { |
if (snd_pcm_hw_params_test_periods(pcm_handle, hwparams, numfragments, dir) < 0) { |
189 |
snd_pcm_close(pcm_handle); |
snd_pcm_close(pcm_handle); |
190 |
return false; |
return false; |
191 |
} |
} |
198 |
return true; |
return true; |
199 |
} |
} |
200 |
|
|
201 |
|
/** |
202 |
|
* Will be called by the audio engine after every audio fragment cycle, to |
203 |
|
* output the audio data of the current fragment to the soundcard. |
204 |
|
* |
205 |
|
* @returns 0 on success |
206 |
|
*/ |
207 |
int AudioIO::Output() { |
int AudioIO::Output() { |
208 |
int err = snd_pcm_writei(pcm_handle, pOutputBuffer, FragmentSize); |
int err = snd_pcm_writei(pcm_handle, pOutputBuffer, FragmentSize); |
209 |
if (err < 0) { |
if (err < 0) { |