本文整理汇总了C++中AudioContext::createBuffer方法的典型用法代码示例。如果您正苦于以下问题:C++ AudioContext::createBuffer方法的具体用法?C++ AudioContext::createBuffer怎么用?C++ AudioContext::createBuffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AudioContext
的用法示例。
在下文中一共展示了AudioContext::createBuffer方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: throwError
v8::Handle<v8::Value> V8AudioContext::createBufferCallback(const v8::Arguments& args)
{
if (args.Length() < 2)
return throwError("Not enough arguments", V8Proxy::SyntaxError);
AudioContext* audioContext = toNative(args.Holder());
ASSERT(audioContext);
v8::Handle<v8::Value> arg = args[0];
// AudioBuffer createBuffer(in ArrayBuffer buffer, in boolean mixToMono);
if (V8ArrayBuffer::HasInstance(arg)) {
v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(arg);
ArrayBuffer* arrayBuffer = V8ArrayBuffer::toNative(object);
ASSERT(arrayBuffer);
if (arrayBuffer) {
bool mixToMono = args[1]->ToBoolean()->Value();
RefPtr<AudioBuffer> audioBuffer = audioContext->createBuffer(arrayBuffer, mixToMono);
if (!audioBuffer.get())
return throwError("Error decoding audio file data", V8Proxy::SyntaxError);
return toV8(audioBuffer.get());
}
return v8::Undefined();
}
// AudioBuffer createBuffer(in unsigned long numberOfChannels, in unsigned long numberOfFrames, in float sampleRate);
if (args.Length() < 3)
return throwError("Not enough arguments", V8Proxy::SyntaxError);
bool ok = false;
int32_t numberOfChannels = toInt32(args[0], ok);
if (!ok || numberOfChannels <= 0 || numberOfChannels > 10)
return throwError("Invalid number of channels", V8Proxy::SyntaxError);
int32_t numberOfFrames = toInt32(args[1], ok);
if (!ok || numberOfFrames <= 0)
return throwError("Invalid number of frames", V8Proxy::SyntaxError);
float sampleRate = toFloat(args[2]);
RefPtr<AudioBuffer> audioBuffer = audioContext->createBuffer(numberOfChannels, numberOfFrames, sampleRate);
if (!audioBuffer.get())
return throwError("Error creating AudioBuffer", V8Proxy::SyntaxError);
return toV8(audioBuffer.get());
}
示例2: createBuffer
JSValue JSAudioContext::createBuffer(ExecState* exec)
{
if (exec->argumentCount() < 2)
return throwError(exec, createSyntaxError(exec, "Not enough arguments"));
AudioContext* audioContext = static_cast<AudioContext*>(impl());
ASSERT(audioContext);
// AudioBuffer createBuffer(in ArrayBuffer buffer, in boolean mixToMono);
JSValue val = exec->argument(0);
if (val.inherits(&JSArrayBuffer::s_info)) {
ArrayBuffer* arrayBuffer = toArrayBuffer(val);
ASSERT(arrayBuffer);
if (arrayBuffer) {
bool mixToMono = exec->argument(1).toBoolean(exec);
RefPtr<AudioBuffer> audioBuffer = audioContext->createBuffer(arrayBuffer, mixToMono);
if (!audioBuffer.get())
return throwError(exec, createSyntaxError(exec, "Error decoding audio file data"));
return toJS(exec, globalObject(), audioBuffer.get());
}
return jsUndefined();
}
// AudioBuffer createBuffer(in unsigned long numberOfChannels, in unsigned long numberOfFrames, in float sampleRate);
if (exec->argumentCount() < 3)
return throwError(exec, createSyntaxError(exec, "Not enough arguments"));
int32_t numberOfChannels = exec->argument(0).toInt32(exec);
int32_t numberOfFrames = exec->argument(1).toInt32(exec);
float sampleRate = exec->argument(2).toFloat(exec);
if (numberOfChannels <= 0 || numberOfChannels > 10)
return throwError(exec, createSyntaxError(exec, "Invalid number of channels"));
if (numberOfFrames <= 0)
return throwError(exec, createSyntaxError(exec, "Invalid number of frames"));
if (sampleRate <= 0)
return throwError(exec, createSyntaxError(exec, "Invalid sample rate"));
RefPtr<AudioBuffer> audioBuffer = audioContext->createBuffer(numberOfChannels, numberOfFrames, sampleRate);
if (!audioBuffer.get())
return throwError(exec, createSyntaxError(exec, "Error creating AudioBuffer"));
return toJS(exec, globalObject(), audioBuffer.get());
}