Skip to content

Commit

Permalink
Merge pull request #93 from usineur/mixer
Browse files Browse the repository at this point in the history
Use Mix_Music instead of Mix_Chunk to play music files.
  • Loading branch information
NagyD committed Oct 2, 2016
2 parents dda8b52 + 95b6734 commit e7b71e0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
31 changes: 26 additions & 5 deletions src/seg009.c
Original file line number Diff line number Diff line change
Expand Up @@ -1515,6 +1515,7 @@ void stop_digi() {
SDL_UnlockAudio();
#else
Mix_HaltChannel(-1);
Mix_HaltMusic();
digi_playing = 0;
#endif
}
Expand Down Expand Up @@ -1605,6 +1606,9 @@ void channel_finished(int channel) {
event.user.code = userevent_SOUND;
SDL_PushEvent(&event);
}
void music_finished() {
channel_finished(-1);
}
#endif

int digi_unavailable = 0;
Expand Down Expand Up @@ -1638,6 +1642,7 @@ void init_digi() {
}
Mix_AllocateChannels(1);
Mix_ChannelFinished(channel_finished);
Mix_HookMusicFinished(music_finished);
#endif
digi_audiospec = desired;
}
Expand Down Expand Up @@ -1701,16 +1706,16 @@ sound_buffer_type* load_sound(int index) {
if (stat(filename, &info))
continue;
//printf("Trying to load %s\n", filename);
Mix_Chunk* chunk = Mix_LoadWAV(filename);
if (chunk == NULL) {
Mix_Music* music = Mix_LoadMUS(filename);
if (music == NULL) {
sdlperror(filename);
//sdlperror("Mix_LoadWAV");
continue;
}
//printf("Loaded sound from %s\n", filename);
result = malloc(sizeof(sound_buffer_type));
result->type = sound_chunk;
result->chunk = chunk;
result->type = sound_music;
result->music = music;
break;
}
} else {
Expand Down Expand Up @@ -1744,6 +1749,16 @@ void __pascal far play_chunk_sound(sound_buffer_type far *buffer) {
digi_playing = 1;
}

void __pascal far play_music_sound(sound_buffer_type far *buffer) {
init_digi();
if (digi_unavailable) return;
stop_sounds();
if (Mix_PlayMusic(buffer->music, 0) == -1) {
sdlperror("Mix_PlayMusic");
}
digi_playing = 1;
}

Uint32 fourcc(char* string) {
return *(Uint32*)string;
}
Expand Down Expand Up @@ -1865,6 +1880,9 @@ void free_sound(sound_buffer_type far *buffer) {
if (buffer->type == sound_chunk) {
Mix_FreeChunk(buffer->chunk);
}
if (buffer->type == sound_music) {
Mix_FreeMusic(buffer->music);
}
#endif
free(buffer);
}
Expand All @@ -1877,7 +1895,7 @@ void __pascal far play_sound_from_buffer(sound_buffer_type far *buffer) {
//quit(1);
return;
}
switch (buffer->type & 3) {
switch (buffer->type & 7) {
case sound_speaker:
play_speaker_sound(buffer);
break;
Expand All @@ -1888,6 +1906,9 @@ void __pascal far play_sound_from_buffer(sound_buffer_type far *buffer) {
case sound_chunk:
play_chunk_sound(buffer);
break;
case sound_music:
play_music_sound(buffer);
break;
#endif
default:
printf("Tried to play unimplemented sound type %d.\n", buffer->type);
Expand Down
2 changes: 2 additions & 0 deletions src/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,7 @@ typedef enum data_location {
enum sound_type {
#ifdef USE_MIXER
sound_chunk = 3,
sound_music = 4,
#endif
sound_speaker = 0,
sound_digi = 1,
Expand Down Expand Up @@ -522,6 +523,7 @@ typedef struct sound_buffer_type {
midi_type midi;
#ifdef USE_MIXER
Mix_Chunk *chunk;
Mix_Music *music;
#endif
};
} sound_buffer_type;
Expand Down

0 comments on commit e7b71e0

Please sign in to comment.