2006-02-25 09:39:15 +01:00
|
|
|
// Copyright (c) 2005-2006, Rodrigo Braz Monteiro, Fredrik Mellbin
|
2006-02-25 07:52:07 +01:00
|
|
|
// 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-02-25 07:52:07 +01:00
|
|
|
//
|
2009-07-29 07:43:02 +02:00
|
|
|
// $Id$
|
|
|
|
|
|
|
|
/// @file audio_provider_avs.cpp
|
|
|
|
/// @brief Avisynth-based audio provider
|
|
|
|
/// @ingroup audio_input
|
|
|
|
///
|
2006-02-25 07:52:07 +01:00
|
|
|
|
|
|
|
|
|
|
|
///////////
|
|
|
|
// Headers
|
2009-01-04 07:31:48 +01:00
|
|
|
#include "config.h"
|
|
|
|
|
2008-01-22 03:54:16 +01:00
|
|
|
#ifdef WITH_AVISYNTH
|
2009-09-10 15:06:40 +02:00
|
|
|
|
|
|
|
|
|
|
|
#ifndef AGI_PRE
|
2006-02-25 07:52:07 +01:00
|
|
|
#include <Mmreg.h>
|
2007-01-23 05:42:08 +01:00
|
|
|
#include <time.h>
|
2009-09-10 15:06:40 +02:00
|
|
|
|
|
|
|
#include <wx/filename.h>
|
|
|
|
#endif
|
|
|
|
|
2008-03-05 03:19:50 +01:00
|
|
|
#include "audio_provider_avs.h"
|
2009-09-10 15:06:40 +02:00
|
|
|
#include "charset_conv.h"
|
2006-02-25 07:52:07 +01:00
|
|
|
#include "options.h"
|
2007-08-28 23:34:44 +02:00
|
|
|
#include "standard_paths.h"
|
2009-09-10 15:06:40 +02:00
|
|
|
#include "utils.h"
|
2006-02-25 07:52:07 +01: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
|
|
|
|
/// @param _filename
|
|
|
|
///
|
2009-07-23 17:16:53 +02:00
|
|
|
AvisynthAudioProvider::AvisynthAudioProvider(wxString _filename) {
|
2009-07-23 21:57:57 +02:00
|
|
|
filename = _filename;
|
2006-02-25 07:52:07 +01:00
|
|
|
|
|
|
|
try {
|
|
|
|
OpenAVSAudio();
|
|
|
|
}
|
|
|
|
catch (...) {
|
|
|
|
Unload();
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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-02-25 07:52:07 +01:00
|
|
|
AvisynthAudioProvider::~AvisynthAudioProvider() {
|
|
|
|
Unload();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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 Unload audio
|
|
|
|
///
|
2006-02-25 07:52:07 +01:00
|
|
|
void AvisynthAudioProvider::Unload() {
|
|
|
|
// Clean up avisynth
|
|
|
|
clip = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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 Load audio from avisynth
|
|
|
|
///
|
2006-02-25 07:52:07 +01:00
|
|
|
void AvisynthAudioProvider::OpenAVSAudio() {
|
|
|
|
// Set variables
|
|
|
|
AVSValue script;
|
|
|
|
|
|
|
|
// Prepare avisynth
|
|
|
|
wxMutexLocker lock(AviSynthMutex);
|
|
|
|
|
|
|
|
try {
|
2007-06-23 08:46:42 +02:00
|
|
|
// Include
|
|
|
|
if (filename.EndsWith(_T(".avs"))) {
|
|
|
|
wxFileName fn(filename);
|
2009-07-14 23:28:49 +02:00
|
|
|
char *fname = env->SaveString(fn.GetShortPath().mb_str(csConvLocal));
|
2007-06-23 08:46:42 +02:00
|
|
|
script = env->Invoke("Import", fname);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Use DirectShowSource
|
|
|
|
else {
|
2007-07-27 07:25:51 +02:00
|
|
|
wxFileName fn(filename);
|
2007-06-23 08:46:42 +02:00
|
|
|
const char * argnames[3] = { 0, "video", "audio" };
|
2009-07-14 23:28:49 +02:00
|
|
|
AVSValue args[3] = { env->SaveString(fn.GetShortPath().mb_str(csConvLocal)), false, true };
|
2007-08-28 23:34:44 +02:00
|
|
|
|
|
|
|
// Load DirectShowSource.dll from app dir if it exists
|
|
|
|
wxFileName dsspath(StandardPaths::DecodePath(_T("?data/DirectShowSource.dll")));
|
|
|
|
if (dsspath.FileExists()) {
|
2009-07-14 23:28:49 +02:00
|
|
|
env->Invoke("LoadPlugin",env->SaveString(dsspath.GetShortPath().mb_str(csConvLocal)));
|
2007-08-28 23:34:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Load audio with DSS if it exists
|
|
|
|
if (env->FunctionExists("DirectShowSource")) {
|
|
|
|
script = env->Invoke("DirectShowSource", AVSValue(args,3),argnames);
|
|
|
|
}
|
|
|
|
// Otherwise fail
|
|
|
|
else {
|
|
|
|
throw AvisynthError("No suitable audio source filter found. Try placing DirectShowSource.dll in the Aegisub application directory.");
|
|
|
|
}
|
2007-06-23 08:46:42 +02:00
|
|
|
}
|
2006-02-25 07:52:07 +01:00
|
|
|
|
|
|
|
LoadFromClip(script);
|
2006-02-25 09:39:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
catch (AvisynthError &err) {
|
2009-07-14 23:28:49 +02:00
|
|
|
throw wxString::Format(_T("AviSynth error: %s"), wxString(err.msg,csConvLocal));
|
2006-02-25 07:52:07 +01: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 Read from environment
|
|
|
|
/// @param _clip
|
|
|
|
///
|
2006-02-25 07:52:07 +01:00
|
|
|
void AvisynthAudioProvider::LoadFromClip(AVSValue _clip) {
|
|
|
|
// Prepare avisynth
|
|
|
|
AVSValue script;
|
|
|
|
|
|
|
|
// Check if it has audio
|
|
|
|
VideoInfo vi = _clip.AsClip()->GetVideoInfo();
|
|
|
|
if (!vi.HasAudio()) throw wxString(_T("No audio found."));
|
|
|
|
|
|
|
|
// Convert to one channel
|
|
|
|
char buffer[1024];
|
2009-07-14 23:28:49 +02:00
|
|
|
strcpy(buffer,Options.AsText(_T("Audio Downmixer")).mb_str(csConvLocal));
|
2006-02-25 07:52:07 +01:00
|
|
|
script = env->Invoke(buffer, _clip);
|
|
|
|
|
|
|
|
// Convert to 16 bits per sample
|
|
|
|
script = env->Invoke("ConvertAudioTo16bit", script);
|
2008-01-19 03:38:31 +01:00
|
|
|
vi = script.AsClip()->GetVideoInfo();
|
2006-02-25 07:52:07 +01:00
|
|
|
|
|
|
|
// Convert sample rate
|
|
|
|
int setsample = Options.AsInt(_T("Audio Sample Rate"));
|
2008-01-19 03:38:31 +01:00
|
|
|
if (vi.SamplesPerSecond() < 32000) setsample = 44100;
|
2006-02-25 07:52:07 +01:00
|
|
|
if (setsample != 0) {
|
|
|
|
AVSValue args[2] = { script, setsample };
|
|
|
|
script = env->Invoke("ResampleAudio", AVSValue(args,2));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set clip
|
|
|
|
PClip tempclip = script.AsClip();
|
|
|
|
vi = tempclip->GetVideoInfo();
|
|
|
|
|
|
|
|
// Read properties
|
|
|
|
channels = vi.AudioChannels();
|
|
|
|
num_samples = vi.num_audio_samples;
|
|
|
|
sample_rate = vi.SamplesPerSecond();
|
|
|
|
bytes_per_sample = vi.BytesPerAudioSample();
|
|
|
|
|
2006-02-25 09:26:29 +01:00
|
|
|
// Set
|
|
|
|
clip = tempclip;
|
2006-02-25 07:52:07 +01: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 Get filename
|
|
|
|
/// @return
|
|
|
|
///
|
2006-02-25 07:52:07 +01:00
|
|
|
wxString AvisynthAudioProvider::GetFilename() {
|
|
|
|
return filename;
|
|
|
|
}
|
|
|
|
|
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 AvisynthAudioProvider::GetAudio(void *buf, int64_t start, int64_t count) {
|
2006-02-25 07:52:07 +01:00
|
|
|
// Requested beyond the length of audio
|
|
|
|
if (start+count > num_samples) {
|
2007-08-31 16:11:35 +02:00
|
|
|
int64_t oldcount = count;
|
2006-02-25 07:52:07 +01:00
|
|
|
count = num_samples-start;
|
|
|
|
if (count < 0) count = 0;
|
|
|
|
|
|
|
|
// Fill beyond with zero
|
|
|
|
if (bytes_per_sample == 1) {
|
|
|
|
char *temp = (char *) buf;
|
|
|
|
for (int i=count;i<oldcount;i++) {
|
|
|
|
temp[i] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (bytes_per_sample == 2) {
|
|
|
|
short *temp = (short *) buf;
|
|
|
|
for (int i=count;i<oldcount;i++) {
|
|
|
|
temp[i] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count) {
|
2006-02-25 09:39:15 +01:00
|
|
|
clip->GetAudio(buf,start,count,env);
|
2006-02-25 07:52:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
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
|
|
|
|