2006-07-04 07:10:29 +02:00
|
|
|
// Copyright (c) 2006, 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/
|
2006-07-04 07:10:29 +02:00
|
|
|
//
|
2009-07-29 07:43:02 +02:00
|
|
|
// $Id$
|
|
|
|
|
|
|
|
/// @file audio_provider_stream.cpp
|
|
|
|
/// @brief Unused aggregate audio provider, intended to be used for audio scrubbing feature
|
|
|
|
/// @ingroup audio_input
|
|
|
|
///
|
2006-07-04 07:10:29 +02:00
|
|
|
|
|
|
|
|
|
|
|
///////////
|
|
|
|
// Headers
|
2009-01-04 07:31:48 +01:00
|
|
|
#include "config.h"
|
|
|
|
|
2006-07-04 07:10:29 +02:00
|
|
|
#include "audio_provider_stream.h"
|
|
|
|
#include "utils.h"
|
|
|
|
|
|
|
|
|
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
|
|
|
/// DOCME
|
2006-07-04 10:25:54 +02:00
|
|
|
#define BUFSIZE 65536
|
2006-07-04 09:00:58 +02:00
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
/// @brief Constructor
|
|
|
|
///
|
2006-07-04 07:10:29 +02:00
|
|
|
StreamAudioProvider::StreamAudioProvider() {
|
|
|
|
bufLen = 8192;
|
|
|
|
startPos = 0;
|
2006-07-04 09:00:58 +02:00
|
|
|
endPos = BUFSIZE;
|
|
|
|
buffered = 0;
|
|
|
|
hasBuf = false;
|
2006-07-08 00:47:55 +02:00
|
|
|
num_samples = ~0ULL;
|
2006-07-04 07:10:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
/// @brief Destructor
|
|
|
|
///
|
2006-07-04 07:10:29 +02:00
|
|
|
StreamAudioProvider::~StreamAudioProvider() {
|
|
|
|
for (std::list<BufferChunk*>::iterator cur=buffer.begin();cur!=buffer.end();cur++) {
|
|
|
|
delete *cur;
|
|
|
|
}
|
|
|
|
buffer.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
/// @brief Get audio
|
|
|
|
/// @param buf
|
|
|
|
/// @param start
|
|
|
|
/// @param count
|
|
|
|
///
|
2007-08-31 16:11:35 +02:00
|
|
|
void StreamAudioProvider::GetAudio(void *buf, int64_t start, int64_t count) {
|
2006-07-04 07:10:29 +02:00
|
|
|
// Write
|
2007-08-31 16:11:35 +02:00
|
|
|
int64_t left = count;
|
2006-07-04 10:25:54 +02:00
|
|
|
int written = 0;
|
2006-07-04 07:10:29 +02:00
|
|
|
int toWrite;
|
2006-07-04 10:25:54 +02:00
|
|
|
short *dst = (short*) buf;
|
2006-07-04 09:00:58 +02:00
|
|
|
while (hasBuf && left > 0) {
|
2006-07-04 07:10:29 +02:00
|
|
|
// Discard done
|
2006-07-04 09:00:58 +02:00
|
|
|
if (startPos == BUFSIZE) {
|
2006-07-04 10:25:54 +02:00
|
|
|
delete buffer.front();
|
2006-07-04 07:10:29 +02:00
|
|
|
buffer.pop_front();
|
|
|
|
startPos = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Is last?
|
|
|
|
bool isLast = buffer.size() == 1;
|
2006-07-04 09:00:58 +02:00
|
|
|
int size = BUFSIZE;
|
2006-07-04 07:10:29 +02:00
|
|
|
if (isLast) size = endPos;
|
|
|
|
|
|
|
|
// Write
|
2006-07-04 10:25:54 +02:00
|
|
|
toWrite = MIN(size-startPos,int(left));
|
|
|
|
memcpy(dst+written,&(buffer.front()->buf[startPos]),toWrite*2);
|
2006-07-04 07:10:29 +02:00
|
|
|
startPos += toWrite;
|
|
|
|
written += toWrite;
|
|
|
|
left -= toWrite;
|
2006-07-04 09:00:58 +02:00
|
|
|
buffered -= toWrite;
|
2006-07-04 07:10:29 +02:00
|
|
|
|
|
|
|
// Last
|
|
|
|
if (isLast) break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Still left, fill with zero
|
|
|
|
if (left > 0) {
|
2006-07-04 09:00:58 +02:00
|
|
|
hasBuf = false;
|
2007-08-31 16:11:35 +02:00
|
|
|
for (int64_t i=written;i<count;i++) {
|
2006-07-04 07:10:29 +02:00
|
|
|
dst[i] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
/// @brief Append audio to stream
|
|
|
|
/// @param voidptr
|
|
|
|
/// @param count
|
|
|
|
///
|
2007-08-31 16:11:35 +02:00
|
|
|
void StreamAudioProvider::Append(void *voidptr, int64_t count) {
|
2006-07-04 07:10:29 +02:00
|
|
|
// Read
|
2007-08-31 16:11:35 +02:00
|
|
|
int64_t left = count;
|
2006-07-04 10:25:54 +02:00
|
|
|
int read = 0;
|
2006-07-04 07:10:29 +02:00
|
|
|
int toRead;
|
2006-07-04 10:25:54 +02:00
|
|
|
short *src = (short*) voidptr;
|
2006-07-04 07:10:29 +02:00
|
|
|
while (left > 0) {
|
|
|
|
// Check space
|
2006-07-04 09:00:58 +02:00
|
|
|
if (endPos == BUFSIZE) {
|
2006-07-04 07:10:29 +02:00
|
|
|
buffer.push_back(new BufferChunk);
|
|
|
|
endPos = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Read
|
2006-07-04 09:00:58 +02:00
|
|
|
toRead = MIN(int(BUFSIZE-endPos),int(left));
|
2006-07-04 10:25:54 +02:00
|
|
|
memcpy(&(buffer.back()->buf[endPos]),src+read,toRead*2);
|
2006-07-04 07:10:29 +02:00
|
|
|
endPos += toRead;
|
|
|
|
read += toRead;
|
2006-07-04 09:00:58 +02:00
|
|
|
buffered += toRead;
|
2006-07-04 07:10:29 +02:00
|
|
|
left -= toRead;
|
|
|
|
}
|
2006-07-04 09:00:58 +02:00
|
|
|
|
|
|
|
// Set buffered status
|
|
|
|
if (buffered > bufLen) hasBuf = true;
|
2006-07-04 07:10:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
/// @brief Set parameters
|
|
|
|
/// @param chan
|
|
|
|
/// @param rate
|
|
|
|
/// @param bps
|
|
|
|
///
|
2006-07-04 08:13:54 +02:00
|
|
|
void StreamAudioProvider::SetParams(int chan,int rate,int bps) {
|
|
|
|
channels = chan;
|
|
|
|
sample_rate = rate;
|
|
|
|
bytes_per_sample = bps;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
/// @brief Buffer chunk constructor
|
|
|
|
///
|
2006-07-04 07:10:29 +02:00
|
|
|
StreamAudioProvider::BufferChunk::BufferChunk() {
|
2006-07-04 09:00:58 +02:00
|
|
|
buf.resize(BUFSIZE);
|
2006-07-04 07:10:29 +02:00
|
|
|
isFree = true;
|
|
|
|
}
|
2009-07-29 07:43:02 +02:00
|
|
|
|
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
|
|
|
|