2008-03-05 03:43:01 +01:00
|
|
|
// Copyright (c) 2005-2007, Rodrigo Braz Monteiro
|
|
|
|
// All rights reserved.
|
|
|
|
//
|
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer in the documentation
|
|
|
|
// and/or other materials provided with the distribution.
|
|
|
|
// * Neither the name of the Aegisub Group nor the names of its contributors
|
|
|
|
// may be used to endorse or promote products derived from this software
|
|
|
|
// without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
// POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
//
|
2009-07-29 07:43:02 +02:00
|
|
|
// Aegisub Project http://www.aegisub.org/
|
|
|
|
|
|
|
|
/// @file audio_player_portaudio.h
|
|
|
|
/// @see audio_player_portaudio.cpp
|
|
|
|
/// @ingroup audio_output
|
|
|
|
///
|
2008-03-05 03:43:01 +01:00
|
|
|
|
|
|
|
#ifdef WITH_PORTAUDIO
|
|
|
|
|
2008-03-07 22:00:20 +01:00
|
|
|
#include "include/aegisub/audio_player.h"
|
2010-08-02 08:32:01 +02:00
|
|
|
|
2010-08-02 10:03:58 +02:00
|
|
|
extern "C" {
|
2008-03-05 03:43:01 +01:00
|
|
|
#include <portaudio.h>
|
|
|
|
}
|
|
|
|
|
2012-01-08 02:33:39 +01:00
|
|
|
#include <map>
|
|
|
|
#include <string>
|
2012-01-23 22:14:32 +01:00
|
|
|
#include <vector>
|
2011-11-28 21:01:46 +01:00
|
|
|
|
2012-03-20 00:31:33 +01:00
|
|
|
class wxArrayString;
|
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
/// @class PortAudioPlayer
|
2009-07-30 04:51:42 +02:00
|
|
|
/// @brief PortAudio Player
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
///
|
2008-03-05 03:43:01 +01:00
|
|
|
class PortAudioPlayer : public AudioPlayer {
|
2012-01-23 22:14:32 +01:00
|
|
|
typedef std::vector<PaDeviceIndex> DeviceVec;
|
|
|
|
/// Map of supported output devices from name -> device index
|
|
|
|
std::map<std::string, DeviceVec> devices;
|
|
|
|
|
|
|
|
/// The index of the default output devices sorted by host API priority
|
|
|
|
DeviceVec default_device;
|
|
|
|
|
2013-12-12 01:29:48 +01:00
|
|
|
float volume = 1.f; ///< Current volume level
|
|
|
|
int64_t current = 0; ///< Current position
|
|
|
|
int64_t start = 0; ///< Start position
|
|
|
|
int64_t end = 0; ///< End position
|
|
|
|
PaTime pa_start; ///< PortAudio internal start position
|
2011-11-28 21:01:46 +01:00
|
|
|
|
2013-12-12 01:29:48 +01:00
|
|
|
PaStream *stream = nullptr; ///< PortAudio stream
|
2011-11-28 21:01:46 +01:00
|
|
|
|
|
|
|
/// @brief PortAudio callback, used to fill buffer for playback, and prime the playback buffer.
|
|
|
|
/// @param inputBuffer Input buffer.
|
|
|
|
/// @param outputBuffer Output buffer.
|
|
|
|
/// @param framesPerBuffer Frames per buffer.
|
|
|
|
/// @param timeInfo PortAudio time information.
|
|
|
|
/// @param statusFlags Status flags
|
|
|
|
/// @param userData Local data to hand callback
|
|
|
|
/// @return Whether to stop playback.
|
2009-06-10 06:45:57 +02:00
|
|
|
static int paCallback(
|
|
|
|
const void *inputBuffer,
|
|
|
|
void *outputBuffer,
|
2008-03-05 03:43:01 +01:00
|
|
|
unsigned long framesPerBuffer,
|
2009-06-10 06:45:57 +02:00
|
|
|
const PaStreamCallbackTimeInfo*
|
|
|
|
timeInfo,
|
|
|
|
PaStreamCallbackFlags
|
|
|
|
statusFlags,
|
|
|
|
void *userData);
|
|
|
|
|
2011-11-28 21:01:46 +01:00
|
|
|
/// @brief Called when the callback has finished.
|
|
|
|
/// @param userData Local data to be handed to the callback.
|
2009-06-10 06:45:57 +02:00
|
|
|
static void paStreamFinishedCallback(void *userData);
|
2008-03-05 03:43:01 +01:00
|
|
|
|
2012-01-23 22:14:32 +01:00
|
|
|
/// Gather the list of output devices supported by a host API
|
|
|
|
/// @param host_idx Host API ID
|
|
|
|
void GatherDevices(PaHostApiIndex host_idx);
|
|
|
|
|
2012-03-20 00:31:33 +01:00
|
|
|
void OpenStream();
|
|
|
|
|
2008-03-05 03:43:01 +01:00
|
|
|
public:
|
2011-11-28 21:01:46 +01:00
|
|
|
/// @brief Constructor
|
2012-03-20 00:31:33 +01:00
|
|
|
PortAudioPlayer(AudioProvider *provider);
|
2012-01-23 22:14:32 +01:00
|
|
|
|
2011-11-28 21:01:46 +01:00
|
|
|
/// @brief Destructor
|
2008-03-05 03:43:01 +01:00
|
|
|
~PortAudioPlayer();
|
|
|
|
|
2011-11-28 21:01:46 +01:00
|
|
|
/// @brief Play audio.
|
|
|
|
/// @param start Start position.
|
|
|
|
/// @param count Frame count
|
2008-03-05 03:43:01 +01:00
|
|
|
void Play(int64_t start,int64_t count);
|
2011-11-28 21:01:46 +01:00
|
|
|
/// @brief Stop Playback
|
|
|
|
/// @param timerToo Stop display timer?
|
2012-03-25 06:05:44 +02:00
|
|
|
void Stop();
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
2009-07-30 04:51:42 +02:00
|
|
|
/// @brief Whether audio is currently being played.
|
|
|
|
/// @return Status
|
2009-08-21 22:08:58 +02:00
|
|
|
bool IsPlaying();
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
2009-07-30 04:51:42 +02:00
|
|
|
/// @brief End position playback will stop at.
|
|
|
|
/// @return End position.
|
2011-11-28 21:01:46 +01:00
|
|
|
int64_t GetEndPosition() { return end; }
|
|
|
|
/// @brief Get current stream position.
|
|
|
|
/// @return Stream position
|
2009-06-10 06:45:57 +02:00
|
|
|
int64_t GetCurrentPosition();
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
2009-07-30 04:51:42 +02:00
|
|
|
/// @brief Set end position of playback
|
|
|
|
/// @param pos End position
|
2011-11-28 21:01:46 +01:00
|
|
|
void SetEndPosition(int64_t position) { end = position; }
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
|
|
|
|
2009-07-30 04:51:42 +02:00
|
|
|
/// @brief Set volume level
|
|
|
|
/// @param vol Volume
|
2008-03-05 03:43:01 +01:00
|
|
|
void SetVolume(double vol) { volume = vol; }
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
2009-07-30 04:51:42 +02:00
|
|
|
/// @brief Get current volume level
|
|
|
|
/// @return Volume level
|
2008-03-05 03:43:01 +01:00
|
|
|
double GetVolume() { return volume; }
|
|
|
|
|
2011-11-28 21:01:46 +01:00
|
|
|
/// Get list of available output devices
|
|
|
|
static wxArrayString GetOutputDevices();
|
2008-03-05 03:43:01 +01:00
|
|
|
};
|
2009-06-10 06:45:57 +02:00
|
|
|
#endif //ifdef WITH_PORTAUDIO
|