1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 //Mix_HookMusicFinished
24 
25 #include "ultima/nuvie/core/nuvie_defs.h"
26 #include "ultima/nuvie/sound/adplug/emu_opl.h"
27 #include "ultima/nuvie/sound/adplug/u6m.h"
28 #include "ultima/nuvie/sound/song_adplug.h"
29 #include "ultima/nuvie/sound/sound_manager.h"
30 #include "ultima/nuvie/nuvie.h"
31 
32 namespace Ultima {
33 namespace Nuvie {
34 
SongAdPlug(Audio::Mixer * m,CEmuopl * o)35 SongAdPlug::SongAdPlug(Audio::Mixer *m, CEmuopl *o) {
36 	mixer = m;
37 	opl = o;
38 	samples_left = 0;
39 	stream = NULL;
40 }
41 
~SongAdPlug()42 SongAdPlug::~SongAdPlug() {
43 }
44 
Init(const char * filename,uint16 song_num)45 bool SongAdPlug::Init(const char *filename, uint16 song_num) {
46 	if (filename == NULL)
47 		return false;
48 
49 	m_Filename = filename; // SB-X
50 
51 	stream = new U6AdPlugDecoderStream(opl, string(filename), song_num);
52 
53 	return true;
54 }
55 
Play(bool looping)56 bool SongAdPlug::Play(bool looping) {
57 	// Just in case song is already playing, stop it
58 	Stop();
59 
60 	// Tell the mixer to play the stream
61 	if (stream) {
62 		byte volume = g_engine->getSoundManager()->get_music_volume();
63 		mixer->playStream(Audio::Mixer::kPlainSoundType, &handle, stream, -1, volume, 0, DisposeAfterUse::NO);
64 	}
65 	return true;
66 }
67 
Stop()68 bool SongAdPlug::Stop() {
69 	mixer->stopHandle(handle);
70 	stream->rewind();
71 	return true;
72 }
73 
SetVolume(uint8 volume)74 bool SongAdPlug::SetVolume(uint8 volume) {
75 	mixer->setChannelVolume(handle, volume);
76 	return true;
77 }
78 
79 } // End of namespace Nuvie
80 } // End of namespace Ultima
81