diff options
author | Aaron Giles <aaron@aarongiles.com> | 2012-02-25 19:19:01 +0000 |
---|---|---|
committer | Aaron Giles <aaron@aarongiles.com> | 2012-02-25 19:19:01 +0000 |
commit | 19d720efc1b0b0eeddd3b50902a3a6df19548d8d (patch) | |
tree | 3b683544f1013fad9a2e615f6d20c11301d0f36c | |
parent | 8d021050041cd131d618c2fc52a31c2b90949c69 (diff) |
Expose a static interface for using the sample loader, for any
other sound chips which may need to fetch samples.
-rw-r--r-- | src/emu/sound/samples.c | 25 | ||||
-rw-r--r-- | src/emu/sound/samples.h | 30 |
2 files changed, 26 insertions, 29 deletions
diff --git a/src/emu/sound/samples.c b/src/emu/sound/samples.c index ac7501b5c55..c7ac5fe2af8 100644 --- a/src/emu/sound/samples.c +++ b/src/emu/sound/samples.c @@ -122,10 +122,10 @@ void samples_device::start(UINT8 channel, UINT32 samplenum, bool loop) chan.stream->update(); // update the parameters - loaded_sample &sample = m_sample[samplenum]; + sample_t &sample = m_sample[samplenum]; chan.source = sample.data; - chan.source_length = sample.length; - chan.source_num = (sample.data.count() > 0) ? samplenum : -1; + chan.source_length = sample.data.count(); + chan.source_num = (chan.source_length > 0) ? samplenum : -1; chan.pos = 0; chan.frac = 0; chan.basefreq = sample.frequency; @@ -330,9 +330,9 @@ void samples_device::device_post_load() channel_t &chan = m_channel[channel]; if (chan.source_num >= 0 && chan.source_num < m_sample.count()) { - loaded_sample &sample = m_sample[chan.source_num]; + sample_t &sample = m_sample[chan.source_num]; chan.source = sample.data; - chan.source_length = sample.length; + chan.source_length = sample.data.count(); if (sample.data == NULL) chan.source_num = -1; } @@ -426,7 +426,7 @@ void samples_device::sound_stream_update(sound_stream &stream, stream_sample_t * // sample //------------------------------------------------- -bool samples_device::read_sample(emu_file &file, loaded_sample &sample) +bool samples_device::read_sample(emu_file &file, sample_t &sample) { // read the core header and make sure it's a proper file UINT8 buf[4]; @@ -453,7 +453,7 @@ bool samples_device::read_sample(emu_file &file, loaded_sample &sample) // read_wav_sample - read a WAV file as a sample //------------------------------------------------- -bool samples_device::read_wav_sample(emu_file &file, loaded_sample &sample) +bool samples_device::read_wav_sample(emu_file &file, sample_t &sample) { // we already read the opening 'WAVE' header UINT32 offset = 4; @@ -548,7 +548,6 @@ bool samples_device::read_wav_sample(emu_file &file, loaded_sample &sample) // read the data in if (bits == 8) { - sample.length = length; sample.data.resize(length); file.read(sample.data, length); @@ -560,13 +559,12 @@ bool samples_device::read_wav_sample(emu_file &file, loaded_sample &sample) else { // 16-bit data is fine as-is - sample.length = length / 2; sample.data.resize(length / 2); file.read(sample.data, length); // swap high/low on big-endian systems if (ENDIANNESS_NATIVE != ENDIANNESS_LITTLE) - for (UINT32 sindex = 0; sindex < sample.length; sindex++) + for (UINT32 sindex = 0; sindex < length / 2; sindex++) sample.data[sindex] = LITTLE_ENDIANIZE_INT16(sample.data[sindex]); } return true; @@ -577,14 +575,13 @@ bool samples_device::read_wav_sample(emu_file &file, loaded_sample &sample) // read_flac_sample - read a FLAC file as a sample //------------------------------------------------- -bool samples_device::read_flac_sample(emu_file &file, loaded_sample &sample) +bool samples_device::read_flac_sample(emu_file &file, sample_t &sample) { // seek back to the start of the file file.seek(0, SEEK_SET); // create the FLAC decoder and fill in the sample data flac_decoder decoder(file); - sample.length = decoder.total_samples(); sample.frequency = decoder.sample_rate(); // error if more than 1 channel or not 16bpp @@ -594,8 +591,8 @@ bool samples_device::read_flac_sample(emu_file &file, loaded_sample &sample) return false; // resize the array and read - sample.data.resize(sample.length); - if (!decoder.decode_interleaved(sample.data, sample.length)) + sample.data.resize(decoder.total_samples()); + if (!decoder.decode_interleaved(sample.data, sample.data.count())) return false; // finish up and clean up diff --git a/src/emu/sound/samples.h b/src/emu/sound/samples.h index b9acbaea729..5824299963f 100644 --- a/src/emu/sound/samples.h +++ b/src/emu/sound/samples.h @@ -105,6 +105,17 @@ public: void set_frequency(UINT8 channel, UINT32 frequency); void set_volume(UINT8 channel, float volume); + // helpers + struct sample_t + { + // shouldn't need a copy, but in case it happens, catch it here + sample_t &operator=(const sample_t &rhs) { assert(false); return *this; } + + UINT32 frequency; // frequency of the sample + dynamic_array<INT16> data; // 16-bit signed data + }; + static bool read_sample(emu_file &file, sample_t &sample); + protected: // subclasses can do it this way samples_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock); @@ -119,16 +130,6 @@ protected: private: // internal classes - struct loaded_sample - { - // shouldn't need a copy, but in case it happens, catch it here - loaded_sample &operator=(const loaded_sample &rhs) { assert(false); return *this; } - - UINT32 length; // length in samples - UINT32 frequency; // frequency of the sample - dynamic_array<INT16> data; // 16-bit signed data - }; - struct channel_t { sound_stream * stream; @@ -144,14 +145,13 @@ private: }; // internal helpers - bool read_sample(emu_file &file, loaded_sample &sample); - bool read_wav_sample(emu_file &file, loaded_sample &sample); - bool read_flac_sample(emu_file &file, loaded_sample &sample); + static bool read_wav_sample(emu_file &file, sample_t &sample); + static bool read_flac_sample(emu_file &file, sample_t &sample); void load_samples(); // internal state - dynamic_array<channel_t> m_channel; - dynamic_array<loaded_sample> m_sample; + dynamic_array<channel_t> m_channel; + dynamic_array<sample_t> m_sample; // internal constants static const UINT8 FRAC_BITS = 24; |