mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-06 11:51:58 -04:00
partial work for storing mp3 length
This commit is contained in:
parent
215d23175e
commit
8b84a51bf7
@ -23,17 +23,42 @@
|
|||||||
#include "milesAudioSound.h"
|
#include "milesAudioSound.h"
|
||||||
#include "milesAudioManager.h"
|
#include "milesAudioManager.h"
|
||||||
|
|
||||||
|
#ifndef NDEBUG //[
|
||||||
|
namespace {
|
||||||
|
char
|
||||||
|
getStatusChar(HAUDIO audio) {
|
||||||
|
if (!audio) {
|
||||||
|
return '0'; // NULL.
|
||||||
|
}
|
||||||
|
switch (AIL_quick_status(audio)) {
|
||||||
|
case QSTAT_LOADED:
|
||||||
|
case QSTAT_DONE:
|
||||||
|
return 'r'; // Ready.
|
||||||
|
case QSTAT_PLAYING:
|
||||||
|
return 'p'; // Playing.
|
||||||
|
default:
|
||||||
|
return 'x'; // bad.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#define miles_audio_debug(x) \
|
||||||
|
audio_debug("MilesAudioSound "<<getStatusChar(_audio)<<" \""<<get_name() \
|
||||||
|
<<"\" "<< x )
|
||||||
|
#else //][
|
||||||
|
#define miles_audio_debug(x) ((void)0)
|
||||||
|
#endif //]
|
||||||
|
|
||||||
MilesAudioSound::
|
MilesAudioSound::
|
||||||
MilesAudioSound(MilesAudioManager* manager,
|
MilesAudioSound(MilesAudioManager* manager,
|
||||||
HAUDIO audio, string file_name)
|
HAUDIO audio, string file_name, float length)
|
||||||
: _manager(manager), _file_name(file_name),
|
: _manager(manager), _file_name(file_name),
|
||||||
_start_time(0), _volume(1.0), _balance(0),
|
_start_time(0), _volume(1.0), _balance(0),
|
||||||
_loop_count(1),
|
_loop_count(1), _length(length),
|
||||||
_active(true), _paused(false) {
|
_active(true), _paused(false) {
|
||||||
nassertv(audio);
|
nassertv(audio);
|
||||||
nassertv(!file_name.empty());
|
nassertv(!file_name.empty());
|
||||||
audio_debug("MilesAudioSound::MilesAudioSound(manager=0x"<<(void*)&manager
|
audio_debug("MilesAudioSound(manager=0x"<<(void*)&manager
|
||||||
<<", audio=0x"<<(void*)audio<<", file_name="<<file_name<<")");
|
<<", audio=0x"<<(void*)audio<<", file_name="<<file_name<<")");
|
||||||
// Make our own copy of the sound header data:
|
// Make our own copy of the sound header data:
|
||||||
_audio=AIL_quick_copy(audio);
|
_audio=AIL_quick_copy(audio);
|
||||||
@ -41,14 +66,14 @@ MilesAudioSound(MilesAudioManager* manager,
|
|||||||
|
|
||||||
MilesAudioSound::
|
MilesAudioSound::
|
||||||
~MilesAudioSound() {
|
~MilesAudioSound() {
|
||||||
audio_debug("MilesAudioSound::~MilesAudioSound() "<<get_name());
|
miles_audio_debug("~MilesAudioSound()");
|
||||||
_manager->release_sound(this);
|
_manager->release_sound(this);
|
||||||
AIL_quick_unload(_audio);
|
AIL_quick_unload(_audio);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MilesAudioSound::
|
void MilesAudioSound::
|
||||||
play() {
|
play() {
|
||||||
audio_debug("MilesAudioSound::play() "<<get_name());
|
miles_audio_debug("play()");
|
||||||
if (_active) {
|
if (_active) {
|
||||||
// Start playing:
|
// Start playing:
|
||||||
if (AIL_quick_play(_audio, _loop_count)) {
|
if (AIL_quick_play(_audio, _loop_count)) {
|
||||||
@ -65,25 +90,25 @@ play() {
|
|||||||
|
|
||||||
void MilesAudioSound::
|
void MilesAudioSound::
|
||||||
stop() {
|
stop() {
|
||||||
audio_debug("MilesAudioSound::stop() "<<get_name());
|
miles_audio_debug("stop()");
|
||||||
AIL_quick_halt(_audio);
|
AIL_quick_halt(_audio);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MilesAudioSound::
|
void MilesAudioSound::
|
||||||
set_loop(bool loop) {
|
set_loop(bool loop) {
|
||||||
audio_debug("MilesAudioSound::set_loop(loop="<<loop<<") "<<get_name());
|
miles_audio_debug("set_loop(loop="<<loop<<")");
|
||||||
set_loop_count((loop)?0:1);
|
set_loop_count((loop)?0:1);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MilesAudioSound::
|
bool MilesAudioSound::
|
||||||
get_loop() const {
|
get_loop() const {
|
||||||
audio_debug("MilesAudioSound::get_loop() returning "<<(_loop_count==0));
|
miles_audio_debug("get_loop() returning "<<(_loop_count==0));
|
||||||
return _loop_count == 0;
|
return _loop_count == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MilesAudioSound::
|
void MilesAudioSound::
|
||||||
set_loop_count(unsigned long loop_count) {
|
set_loop_count(unsigned long loop_count) {
|
||||||
audio_debug("MilesAudioSound::set_loop_count(loop_count="<<loop_count<<") "<<get_name());
|
miles_audio_debug("set_loop_count(loop_count="<<loop_count<<")");
|
||||||
if (_loop_count!=loop_count) {
|
if (_loop_count!=loop_count) {
|
||||||
_loop_count=loop_count;
|
_loop_count=loop_count;
|
||||||
if (status()==PLAYING) {
|
if (status()==PLAYING) {
|
||||||
@ -102,13 +127,13 @@ set_loop_count(unsigned long loop_count) {
|
|||||||
|
|
||||||
unsigned long MilesAudioSound::
|
unsigned long MilesAudioSound::
|
||||||
get_loop_count() const {
|
get_loop_count() const {
|
||||||
audio_debug("MilesAudioSound::get_loop_count() returning "<<_loop_count);
|
miles_audio_debug("get_loop_count() returning "<<_loop_count);
|
||||||
return _loop_count;
|
return _loop_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MilesAudioSound::
|
void MilesAudioSound::
|
||||||
set_time(float start_time) {
|
set_time(float start_time) {
|
||||||
audio_debug("MilesAudioSound::set_time(start_time="<<start_time<<") "<<get_name());
|
miles_audio_debug("set_time(start_time="<<start_time<<")");
|
||||||
_start_time=start_time;
|
_start_time=start_time;
|
||||||
S32 milisecond_start_time=S32(1000*_start_time);
|
S32 milisecond_start_time=S32(1000*_start_time);
|
||||||
AIL_quick_set_ms_position(_audio, milisecond_start_time);
|
AIL_quick_set_ms_position(_audio, milisecond_start_time);
|
||||||
@ -116,13 +141,13 @@ set_time(float start_time) {
|
|||||||
|
|
||||||
float MilesAudioSound::
|
float MilesAudioSound::
|
||||||
get_time() const {
|
get_time() const {
|
||||||
audio_debug("MilesAudioSound::get_time() returning "<<_start_time);
|
miles_audio_debug("get_time() returning "<<_start_time);
|
||||||
return _start_time;
|
return _start_time;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MilesAudioSound::
|
void MilesAudioSound::
|
||||||
set_volume(float volume) {
|
set_volume(float volume) {
|
||||||
audio_debug("MilesAudioSound::set_volume(volume="<<volume<<") "<<get_name());
|
miles_audio_debug("set_volume(volume="<<volume<<")");
|
||||||
// *Set the volume even if our volume is not changing, because the
|
// *Set the volume even if our volume is not changing, because the
|
||||||
// *MilesAudioManager will call set_volume when *its* volume changes.
|
// *MilesAudioManager will call set_volume when *its* volume changes.
|
||||||
// Set the volume:
|
// Set the volume:
|
||||||
@ -151,13 +176,13 @@ set_volume(float volume) {
|
|||||||
|
|
||||||
float MilesAudioSound::
|
float MilesAudioSound::
|
||||||
get_volume() const {
|
get_volume() const {
|
||||||
audio_debug("MilesAudioSound::get_volume() returning "<<_volume);
|
miles_audio_debug("get_volume() returning "<<_volume);
|
||||||
return _volume;
|
return _volume;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MilesAudioSound::
|
void MilesAudioSound::
|
||||||
set_active(bool active) {
|
set_active(bool active) {
|
||||||
audio_debug("MilesAudioSound::set_active(active="<<active<<") "<<get_name());
|
miles_audio_debug("set_active(active="<<active<<")");
|
||||||
if (_active!=active) {
|
if (_active!=active) {
|
||||||
_active=active;
|
_active=active;
|
||||||
if (_active) {
|
if (_active) {
|
||||||
@ -184,13 +209,13 @@ set_active(bool active) {
|
|||||||
|
|
||||||
bool MilesAudioSound::
|
bool MilesAudioSound::
|
||||||
get_active() const {
|
get_active() const {
|
||||||
audio_debug("MilesAudioSound::get_active() returning "<<_active);
|
miles_audio_debug("get_active() returning "<<_active);
|
||||||
return _active;
|
return _active;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MilesAudioSound::
|
void MilesAudioSound::
|
||||||
set_balance(float balance_right) {
|
set_balance(float balance_right) {
|
||||||
audio_debug("MilesAudioSound::set_balance(balance_right="<<balance_right<<") "<<get_name());
|
miles_audio_debug("set_balance(balance_right="<<balance_right<<")");
|
||||||
_balance=balance_right;
|
_balance=balance_right;
|
||||||
// Call set_volume to effect the change:
|
// Call set_volume to effect the change:
|
||||||
set_volume(_volume);
|
set_volume(_volume);
|
||||||
@ -204,9 +229,11 @@ get_balance() const {
|
|||||||
|
|
||||||
float MilesAudioSound::
|
float MilesAudioSound::
|
||||||
length() const {
|
length() const {
|
||||||
float length=((float)AIL_quick_ms_length(_audio))*0.001;
|
if (!_length) {
|
||||||
audio_debug("MilesAudioSound::length() returning "<<length);
|
_length=((float)AIL_quick_ms_length(_audio))*0.001;
|
||||||
return length;
|
}
|
||||||
|
miles_audio_debug("length() returning "<<_length);
|
||||||
|
return _length;
|
||||||
}
|
}
|
||||||
|
|
||||||
const string& MilesAudioSound::
|
const string& MilesAudioSound::
|
||||||
|
@ -83,13 +83,14 @@ private:
|
|||||||
float _start_time; // 0..length()
|
float _start_time; // 0..length()
|
||||||
float _volume; // 0..1.0
|
float _volume; // 0..1.0
|
||||||
float _balance; // -1..1
|
float _balance; // -1..1
|
||||||
|
mutable float _length; // in seconds.
|
||||||
unsigned long _loop_count;
|
unsigned long _loop_count;
|
||||||
string _file_name;
|
string _file_name;
|
||||||
bool _active;
|
bool _active;
|
||||||
bool _paused;
|
bool _paused;
|
||||||
|
|
||||||
MilesAudioSound(MilesAudioManager* manager,
|
MilesAudioSound(MilesAudioManager* manager,
|
||||||
HAUDIO audio, string file_name);
|
HAUDIO audio, string file_name, float length=0.0);
|
||||||
|
|
||||||
friend class MilesAudioManager;
|
friend class MilesAudioManager;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user