mirror of
https://github.com/buserror/mii_emu.git
synced 2025-01-08 18:30:25 +00:00
speaker: Allow disabling audio, not just muting
Allow turning off the audio output (ie not initialize it). Also removed the debug file descriptor global Signed-off-by: Michel Pollet <buserror@gmail.com>
This commit is contained in:
parent
cb17359921
commit
2f30c4986c
@ -90,7 +90,8 @@ mii_speaker_init(
|
|||||||
s->mii = mii;
|
s->mii = mii;
|
||||||
s->fsize = MII_SPEAKER_FRAME_SIZE;
|
s->fsize = MII_SPEAKER_FRAME_SIZE;
|
||||||
#ifdef HAS_ALSA
|
#ifdef HAS_ALSA
|
||||||
_alsa_init(s); // this can/will change fsize
|
if (!s->off)
|
||||||
|
_alsa_init(s); // this can/will change fsize
|
||||||
#endif
|
#endif
|
||||||
s->vol_multiplier = 0.2;
|
s->vol_multiplier = 0.2;
|
||||||
s->sample = 0x8000;
|
s->sample = 0x8000;
|
||||||
@ -132,7 +133,8 @@ mii_speaker_click(
|
|||||||
(s->mii->cycles - f->start) > (2 * s->fsize * s->clk_per_sample)) {
|
(s->mii->cycles - f->start) > (2 * s->fsize * s->clk_per_sample)) {
|
||||||
// printf("Restarting playback\n");
|
// printf("Restarting playback\n");
|
||||||
#ifdef HAS_ALSA
|
#ifdef HAS_ALSA
|
||||||
snd_pcm_prepare(s->alsa_pcm);
|
if (s->alsa_pcm)
|
||||||
|
snd_pcm_prepare(s->alsa_pcm);
|
||||||
#endif
|
#endif
|
||||||
f->start = s->mii->cycles - (s->clk_per_sample * 8);
|
f->start = s->mii->cycles - (s->clk_per_sample * 8);
|
||||||
f->fill = 0;
|
f->fill = 0;
|
||||||
@ -166,7 +168,6 @@ mii_speaker_click(
|
|||||||
f->audio[sample_index] = s->sample * s->vol_multiplier;
|
f->audio[sample_index] = s->sample * s->vol_multiplier;
|
||||||
}
|
}
|
||||||
|
|
||||||
int g_mii_audio_record_fd = -1;
|
|
||||||
|
|
||||||
// Check to see if there's a new frame to send, send it
|
// Check to see if there's a new frame to send, send it
|
||||||
void
|
void
|
||||||
@ -186,15 +187,17 @@ mii_speaker_run(
|
|||||||
s->fplay = (s->fplay + 1) % MII_SPEAKER_FRAME_COUNT;
|
s->fplay = (s->fplay + 1) % MII_SPEAKER_FRAME_COUNT;
|
||||||
f = &s->frame[s->fplaying];
|
f = &s->frame[s->fplaying];
|
||||||
if (!s->muted) {
|
if (!s->muted) {
|
||||||
#ifdef HAS_ALSA
|
if (s->debug_fd != -1)
|
||||||
int pcm;
|
write(s->debug_fd, f->audio,
|
||||||
if (g_mii_audio_record_fd != -1)
|
|
||||||
write(g_mii_audio_record_fd, f->audio,
|
|
||||||
f->fill * sizeof(s->frame[0].audio[0]));
|
f->fill * sizeof(s->frame[0].audio[0]));
|
||||||
if ((pcm = snd_pcm_writei(s->alsa_pcm,
|
#ifdef HAS_ALSA
|
||||||
f->audio, f->fill)) == -EPIPE) {
|
if (s->alsa_pcm) {
|
||||||
printf("%s Underrun.\n", __func__);
|
int pcm;
|
||||||
snd_pcm_recover(s->alsa_pcm, pcm, 1);
|
if ((pcm = snd_pcm_writei(s->alsa_pcm,
|
||||||
|
f->audio, f->fill)) == -EPIPE) {
|
||||||
|
printf("%s Underrun.\n", __func__);
|
||||||
|
snd_pcm_recover(s->alsa_pcm, pcm, 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -223,4 +226,4 @@ mii_speaker_volume(
|
|||||||
s->volume = volume;
|
s->volume = volume;
|
||||||
|
|
||||||
// printf("audio: speaker volume set to %.3f (%.4f)\n", volume, mul);
|
// printf("audio: speaker volume set to %.3f (%.4f)\n", volume, mul);
|
||||||
}
|
}
|
||||||
|
@ -24,8 +24,10 @@ typedef struct mii_audio_frame_t {
|
|||||||
|
|
||||||
typedef struct mii_speaker_t {
|
typedef struct mii_speaker_t {
|
||||||
struct mii_t * mii;
|
struct mii_t * mii;
|
||||||
|
int debug_fd; // if > 0, dump audio to this fd
|
||||||
void * alsa_pcm; // alsa pcm handle
|
void * alsa_pcm; // alsa pcm handle
|
||||||
bool muted; // if true, don't play anything
|
bool muted; // if true, don't play anything
|
||||||
|
bool off; // if true, don't even initialize (alsa)
|
||||||
float volume; // volume, 0.0 to 10.0
|
float volume; // volume, 0.0 to 10.0
|
||||||
float vol_multiplier; // sample multiplier, 0.0 to 1.0
|
float vol_multiplier; // sample multiplier, 0.0 to 1.0
|
||||||
float cpu_speed; // CPU speed in MHz, to calculate clk_per_sample
|
float cpu_speed; // CPU speed in MHz, to calculate clk_per_sample
|
||||||
|
Loading…
Reference in New Issue
Block a user