00001 #include "device_ds_buffer.h"
00002 #include "device_ds.h"
00003
00004
00005 namespace audiere {
00006
00007 DSOutputBuffer::DSOutputBuffer(
00008 DSAudioDevice* device,
00009 IDirectSoundBuffer* buffer,
00010 int length,
00011 int frame_size)
00012 {
00013 m_device = device;
00014 m_buffer = buffer;
00015 m_length = length;
00016 m_frame_size = frame_size;
00017
00018 DWORD frequency;
00019 m_buffer->GetFrequency(&frequency);
00020 m_base_frequency = frequency;
00021
00022 m_repeating = false;
00023 m_volume = 1;
00024 m_pan = 0;
00025 }
00026
00027
00028 DSOutputBuffer::~DSOutputBuffer() {
00029 m_buffer->Release();
00030 }
00031
00032
00033 void
00034 DSOutputBuffer::play() {
00035 m_buffer->Play(0, 0, m_repeating ? DSBPLAY_LOOPING : 0);
00036 }
00037
00038
00039 void
00040 DSOutputBuffer::stop() {
00041 m_buffer->Stop();
00042 }
00043
00044
00045 bool
00046 DSOutputBuffer::isPlaying() {
00047 DWORD status;
00048 HRESULT rv = m_buffer->GetStatus(&status);
00049 return (SUCCEEDED(rv) && status & DSBSTATUS_PLAYING);
00050 }
00051
00052
00053 void
00054 DSOutputBuffer::reset() {
00055 setPosition(0);
00056 }
00057
00058
00059 void
00060 DSOutputBuffer::setRepeat(bool repeat) {
00061 m_repeating = repeat;
00062 if (isPlaying()) {
00063
00064 play();
00065 }
00066 }
00067
00068
00069 bool
00070 DSOutputBuffer::getRepeat() {
00071 return m_repeating;
00072 }
00073
00074
00075 void
00076 DSOutputBuffer::setVolume(float volume) {
00077 m_volume = volume;
00078 m_buffer->SetVolume(DSAudioDevice::Volume_AudiereToDirectSound(volume));
00079 }
00080
00081
00082 float
00083 DSOutputBuffer::getVolume() {
00084 return m_volume;
00085 }
00086
00087
00088 void
00089 DSOutputBuffer::setPan(float pan) {
00090 m_pan = pan;
00091 m_buffer->SetPan(DSAudioDevice::Pan_AudiereToDirectSound(pan));
00092 }
00093
00094
00095 float
00096 DSOutputBuffer::getPan() {
00097 return m_pan;
00098 }
00099
00100
00101 void
00102 DSOutputBuffer::setPitchShift(float shift) {
00103 m_buffer->SetFrequency(m_base_frequency * shift);
00104 }
00105
00106
00107 float
00108 DSOutputBuffer::getPitchShift() {
00109 DWORD frequency;
00110 m_buffer->GetFrequency(&frequency);
00111 return float(frequency) / m_base_frequency;
00112 }
00113
00114
00115 bool
00116 DSOutputBuffer::isSeekable() {
00117 return true;
00118 }
00119
00120
00121 int
00122 DSOutputBuffer::getLength() {
00123 return m_length;
00124 }
00125
00126
00127 void
00128 DSOutputBuffer::setPosition(int position) {
00129 m_buffer->SetCurrentPosition(position * m_frame_size);
00130 }
00131
00132
00133 int
00134 DSOutputBuffer::getPosition() {
00135 DWORD play;
00136 m_buffer->GetCurrentPosition(&play, 0);
00137 return play / m_frame_size;
00138 }
00139
00140 }