N64FlashcartMenu/src/menu/sound.c

53 lines
1.1 KiB
C
Raw Normal View History

#include <stdbool.h>
#include <libdragon.h>
#include "mp3_player.h"
#define DEFAULT_FREQUENCY (44100)
#define NUM_BUFFERS (2)
#define NUM_CHANNELS (2)
static bool sound_initialized = false;
2023-08-18 20:19:20 +02:00
static void sound_reconfigure (int frequency) {
if ((frequency > 0) && (audio_get_frequency() != frequency)) {
if (sound_initialized) {
mixer_close();
audio_close();
}
2023-08-18 20:19:20 +02:00
audio_init(frequency, NUM_BUFFERS);
mixer_init(NUM_CHANNELS);
mp3player_mixer_init();
sound_initialized = true;
}
}
2023-08-18 20:19:20 +02:00
void sound_init_default (void) {
sound_reconfigure(DEFAULT_FREQUENCY);
}
void sound_init_mp3_playback (void) {
2023-08-18 20:19:20 +02:00
sound_reconfigure(mp3player_get_samplerate());
}
64DD disk loading support for SummerCart64 (#49) (and other fixes/improvements) <!--- Provide a general summary of your changes in the Title above --> ## Description <!--- Describe your changes in detail --> ## Motivation and Context <!--- What does this sample do? What problem does it solve? --> <!--- If it fixes/closes/resolves an open issue, please link to the issue here --> ## How Has This Been Tested? <!-- (if applicable) --> <!--- Please describe in detail how you tested your sample/changes. --> <!--- Include details of your testing environment, and the tests you ran to --> <!--- see how your change affects other areas of the code, etc. --> ## Screenshots <!-- (if appropriate): --> ## Types of changes <!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: --> - [ ] Improvement (non-breaking change that adds a new feature) - [ ] Bug fix (fixes an issue) - [ ] Breaking change (breaking change) - [ ] Config and build (change in the configuration and build system, has no impact on code or features) ## Checklist: <!--- Go over all the following points, and put an `x` in all the boxes that apply. --> <!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> - [ ] My code follows the code style of this project. - [ ] My change requires a change to the documentation. - [ ] I have updated the documentation accordingly. - [ ] I have added tests to cover my changes. - [ ] All new and existing tests passed. <!--- It would be nice if you could sign off your contribution by replacing the name with your GitHub user name and GitHub email contact. --> Signed-off-by: GITHUB_USER <GITHUB_USER_EMAIL> --------- Signed-off-by: Polprzewodnikowy <sc@mateuszfaderewski.pl> Co-authored-by: Robin Jones <networkfusion@users.noreply.github.com>
2023-10-10 21:12:53 +02:00
void sound_deinit (void) {
if (sound_initialized) {
mixer_close();
audio_close();
sound_initialized = false;
}
}
void sound_poll (void) {
if (sound_initialized && audio_can_write()) {
short *audio_buffer = audio_write_begin();
mixer_poll(audio_buffer, audio_get_buffer_length());
audio_write_end();
}
}