openMSX
LibAOSoundDriver.cc
Go to the documentation of this file.
1 #include "LibAOSoundDriver.hh"
2 #include "MSXException.hh"
3 #include <ao/ao.h>
4 #include <cstring>
5 
6 namespace openmsx {
7 
8 static const int BITS_PER_SAMPLE = 16;
9 static const int CHANNELS = 2;
10 
11 LibAOSoundDriver::LibAOSoundDriver(unsigned sampleRate_, unsigned bufferSize_)
12  : sampleRate(sampleRate_)
13  , bufferSize(bufferSize_)
14 {
15  ao_initialize();
16 
17  int driver = ao_default_driver_id();
18 
19  ao_sample_format format;
20  memset(&format, 0, sizeof(format));
21  format.bits = BITS_PER_SAMPLE;
22  format.channels = CHANNELS;
23  format.rate = sampleRate;
24  format.byte_format = AO_FMT_NATIVE;
25 
26  device = ao_open_live(driver, &format, nullptr /* no options */);
27  if (!device) {
28  throw MSXException("Couldn't open audio device");
29  }
30 }
31 
33 {
34  ao_close(device);
35  ao_shutdown();
36 }
37 
39 {
40 }
41 
43 {
44 }
45 
47 {
48  return sampleRate;
49 }
50 
52 {
53  return bufferSize;
54 }
55 
56 void LibAOSoundDriver::uploadBuffer(short* buffer, unsigned len)
57 {
58  ao_play(device,
59  reinterpret_cast<char*>(buffer),
60  len * CHANNELS * (BITS_PER_SAMPLE / 8));
61 }
62 
63 } // namespace openmsx
virtual void mute()
Mute the sound system.
LibAOSoundDriver(unsigned sampleRate, unsigned bufferSize)
virtual unsigned getFrequency() const
Returns the actual sample frequency.
virtual void uploadBuffer(short *buffer, unsigned len)
void format(SectorAccessibleDisk &disk, bool dos1)
Format the given disk (= a single partition).
virtual void unmute()
Unmute the sound system.
virtual unsigned getSamples() const
Get the number of samples that should be created 'per fragment'.