kandi background
Explore Kits

oboe | Oboe is a C library that makes it easy to build highperformance audio apps on Android.

 by   google C++ Version: 1.6.1 License: Non-SPDX

 by   google C++ Version: 1.6.1 License: Non-SPDX

Download this library from

kandi X-RAY | oboe Summary

oboe is a C++ library. oboe has no bugs, it has no vulnerabilities and it has medium support. However oboe has a Non-SPDX License. You can download it from GitHub.
Oboe is a C++ library which makes it easy to build high-performance audio apps on Android. It was created primarily to allow developers to target a simplified API that works across multiple API levels back to API level 16 (Jelly Bean).
Support
Support
Quality
Quality
Security
Security
License
License
Reuse
Reuse

kandi-support Support

  • oboe has a medium active ecosystem.
  • It has 2965 star(s) with 462 fork(s). There are 139 watchers for this library.
  • It had no major release in the last 12 months.
  • There are 159 open issues and 742 have been closed. On average issues are closed in 78 days. There are 2 open pull requests and 0 closed requests.
  • It has a neutral sentiment in the developer community.
  • The latest version of oboe is 1.6.1
oboe Support
Best in #C++
Average in #C++
oboe Support
Best in #C++
Average in #C++

quality kandi Quality

  • oboe has 0 bugs and 0 code smells.
oboe Quality
Best in #C++
Average in #C++
oboe Quality
Best in #C++
Average in #C++

securitySecurity

  • oboe has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
  • oboe code analysis shows 0 unresolved vulnerabilities.
  • There are 0 security hotspots that need review.
oboe Security
Best in #C++
Average in #C++
oboe Security
Best in #C++
Average in #C++

license License

  • oboe has a Non-SPDX License.
  • Non-SPDX licenses can be open source with a non SPDX compliant license, or non open source licenses, and you need to review them closely before use.
oboe License
Best in #C++
Average in #C++
oboe License
Best in #C++
Average in #C++

buildReuse

  • oboe releases are available to install and integrate.
  • It has 30962 lines of code, 1175 functions and 447 files.
  • It has high code complexity. Code complexity directly impacts maintainability of the code.
oboe Reuse
Best in #C++
Average in #C++
oboe Reuse
Best in #C++
Average in #C++
Top functions reviewed by kandi - BETA

Coming Soon for all Libraries!

Currently covering the most popular Java, JavaScript and Python libraries. See a SAMPLE HERE.
kandi's functional review helps you automatically verify the functionalities of the libraries and avoid rework.

oboe Key Features

Compatible with API 16 onwards - runs on 99% of Android devices

Chooses the audio API (OpenSL ES on API 16+ or AAudio on API 27+) which will give the best audio performance on the target Android device

Automatic latency tuning

Modern C++ allowing you to write clean, elegant code

Workarounds for some known issues

Used by popular apps and frameworks

How can I call function with PointerByReference arguments for a Float[]?

copy iconCopydownload iconDownload
length len = 123; // I assume you know this length

// call the function with your length

Pointer p = leftOut.getValue();
float[] leftArray = p.getFloatArray(0, len);

Pointer q = rightOut.getValue();
float[] rightArray = q.getFloatArray(0, len);
// allocate memory for the float array of size len
Memory m = new Memory(4 * len);
// Memory extends pointer so just pass this to the PBR constructor
PointerByReference leftOut = new PointerByReference(m);
// now pass leftOut to the method
long peer = Pointer.nativeValue(p); // or m or whatever the pointer is
-----------------------
length len = 123; // I assume you know this length

// call the function with your length

Pointer p = leftOut.getValue();
float[] leftArray = p.getFloatArray(0, len);

Pointer q = rightOut.getValue();
float[] rightArray = q.getFloatArray(0, len);
// allocate memory for the float array of size len
Memory m = new Memory(4 * len);
// Memory extends pointer so just pass this to the PBR constructor
PointerByReference leftOut = new PointerByReference(m);
// now pass leftOut to the method
long peer = Pointer.nativeValue(p); // or m or whatever the pointer is
-----------------------
length len = 123; // I assume you know this length

// call the function with your length

Pointer p = leftOut.getValue();
float[] leftArray = p.getFloatArray(0, len);

Pointer q = rightOut.getValue();
float[] rightArray = q.getFloatArray(0, len);
// allocate memory for the float array of size len
Memory m = new Memory(4 * len);
// Memory extends pointer so just pass this to the PBR constructor
PointerByReference leftOut = new PointerByReference(m);
// now pass leftOut to the method
long peer = Pointer.nativeValue(p); // or m or whatever the pointer is

Execution failed for task ':app:externalNativeBuildDebug' when using cpp and java in android

copy iconCopydownload iconDownload
double SoundGenerator::_Frequency = 440.0; // A

How do I avoid loops in R?

copy iconCopydownload iconDownload
library(tidyverse)
thing_to_be_searched %>%
  # Melt wide data to long
  pivot_longer(-1) %>%
  # Drop unwanted column
  select(-name) %>%
  # Filter wanted values only
  filter( value %in% things_I_want_to_find) %>%
  # Only keep unique rows
  unique()
# A tibble: 5 x 2
  id     value        
  <chr>  <chr>        
1 john   vocals       
2 paul   bass         
3 paul   vocals       
4 george rhythm guitar
5 ringo  drums 
-----------------------
library(tidyverse)
thing_to_be_searched %>%
  # Melt wide data to long
  pivot_longer(-1) %>%
  # Drop unwanted column
  select(-name) %>%
  # Filter wanted values only
  filter( value %in% things_I_want_to_find) %>%
  # Only keep unique rows
  unique()
# A tibble: 5 x 2
  id     value        
  <chr>  <chr>        
1 john   vocals       
2 paul   bass         
3 paul   vocals       
4 george rhythm guitar
5 ringo  drums 
-----------------------
library(dplyr)

thing_to_be_searched %>%
  group_by(id) %>%
  summarise(instrument = things_I_want_to_find[things_I_want_to_find %in% cur_data()]) %>%
  ungroup

#   id     instrument   
#  <chr>  <chr>        
#1 george rhythm guitar
#2 john   vocals       
#3 paul   vocals       
#4 paul   bass         
#5 ringo  drums        
-----------------------
thing_to_be_searched |>
   setNames(c('id', paste0('a', 1:3))) |>
   reshape(direction = 'long',  varying  = 2:4, sep="") |>
   subset(a %in% things_I_want_to_find, select = c(id, a)) |>
   unique() |>
   `row.names<-`(NULL)
#      id             a
#1   john        vocals
#2   paul          bass
#3 george rhythm guitar
#4   paul        vocals
#5  ringo         drums

How to handle speaker change with Android Oboe library?

copy iconCopydownload iconDownload
void OboeStreamCallback::onErrorAfterClose(AudioStream *stream, Result result) {
    if (result == oboe::Result::ErrorDisconnected) {
        LOGI("Restarting AudioStream after disconnect");
        soundEngine.restart(); // please check oboe samples for soundEngine.restart(); call
    }
}

How to pan audio sample data naturally?

copy iconCopydownload iconDownload
player->data.at((offset + i) * 2) * 1.0; // left signal at full volume
player->data.at((offset + i) * 2 + 1) * 0.0; // right signal fully attenuated
pan_mapped = ((pan + 1) / 2.0) * (Math.pi / 2.0);

left_amplitude = sin(pan_mapped);
right_amplitude = cos(pan_mapped); 
left_output  += left_source(i)  * sin(left_pan)
right_output += left_source(i)  * cos(left_pan)
left_output  += right_source(i) * sin(right_pan)
right_output += right_source(i) * cos(right_pan)
hPi = math.pi / 2.0
  
def stereoPan(x):
    if (x < 0.0):
        print("left source:")
        print(1.0) # amplitude to left channel
        print(0.0) # amplitude to right channel
        print("right source:")
        print(math.sin(abs(x) * hPi)) # amplitude to left channel
        print(math.cos(abs(x) * hPi)) # amplitude to right channel

    else:
        print("left source:")
        print(math.cos(x * hPi)) # amplitude to left channel
        print(math.sin(x * hPi)) # amplitude to right channel  
        print("right source:")
        print(0.0) # amplitude to left channel
        print(1.0) # amplitude to right channel
-----------------------
player->data.at((offset + i) * 2) * 1.0; // left signal at full volume
player->data.at((offset + i) * 2 + 1) * 0.0; // right signal fully attenuated
pan_mapped = ((pan + 1) / 2.0) * (Math.pi / 2.0);

left_amplitude = sin(pan_mapped);
right_amplitude = cos(pan_mapped); 
left_output  += left_source(i)  * sin(left_pan)
right_output += left_source(i)  * cos(left_pan)
left_output  += right_source(i) * sin(right_pan)
right_output += right_source(i) * cos(right_pan)
hPi = math.pi / 2.0
  
def stereoPan(x):
    if (x < 0.0):
        print("left source:")
        print(1.0) # amplitude to left channel
        print(0.0) # amplitude to right channel
        print("right source:")
        print(math.sin(abs(x) * hPi)) # amplitude to left channel
        print(math.cos(abs(x) * hPi)) # amplitude to right channel

    else:
        print("left source:")
        print(math.cos(x * hPi)) # amplitude to left channel
        print(math.sin(x * hPi)) # amplitude to right channel  
        print("right source:")
        print(0.0) # amplitude to left channel
        print(1.0) # amplitude to right channel
-----------------------
player->data.at((offset + i) * 2) * 1.0; // left signal at full volume
player->data.at((offset + i) * 2 + 1) * 0.0; // right signal fully attenuated
pan_mapped = ((pan + 1) / 2.0) * (Math.pi / 2.0);

left_amplitude = sin(pan_mapped);
right_amplitude = cos(pan_mapped); 
left_output  += left_source(i)  * sin(left_pan)
right_output += left_source(i)  * cos(left_pan)
left_output  += right_source(i) * sin(right_pan)
right_output += right_source(i) * cos(right_pan)
hPi = math.pi / 2.0
  
def stereoPan(x):
    if (x < 0.0):
        print("left source:")
        print(1.0) # amplitude to left channel
        print(0.0) # amplitude to right channel
        print("right source:")
        print(math.sin(abs(x) * hPi)) # amplitude to left channel
        print(math.cos(abs(x) * hPi)) # amplitude to right channel

    else:
        print("left source:")
        print(math.cos(x * hPi)) # amplitude to left channel
        print(math.sin(x * hPi)) # amplitude to right channel  
        print("right source:")
        print(0.0) # amplitude to left channel
        print(1.0) # amplitude to right channel
-----------------------
player->data.at((offset + i) * 2) * 1.0; // left signal at full volume
player->data.at((offset + i) * 2 + 1) * 0.0; // right signal fully attenuated
pan_mapped = ((pan + 1) / 2.0) * (Math.pi / 2.0);

left_amplitude = sin(pan_mapped);
right_amplitude = cos(pan_mapped); 
left_output  += left_source(i)  * sin(left_pan)
right_output += left_source(i)  * cos(left_pan)
left_output  += right_source(i) * sin(right_pan)
right_output += right_source(i) * cos(right_pan)
hPi = math.pi / 2.0
  
def stereoPan(x):
    if (x < 0.0):
        print("left source:")
        print(1.0) # amplitude to left channel
        print(0.0) # amplitude to right channel
        print("right source:")
        print(math.sin(abs(x) * hPi)) # amplitude to left channel
        print(math.cos(abs(x) * hPi)) # amplitude to right channel

    else:
        print("left source:")
        print(math.cos(x * hPi)) # amplitude to left channel
        print(math.sin(x * hPi)) # amplitude to right channel  
        print("right source:")
        print(0.0) # amplitude to left channel
        print(1.0) # amplitude to right channel

How to add protobuf into flutter/kotlin android project

copy iconCopydownload iconDownload
dependencies {
    implementation  "com.google.protobuf:protobuf-javalite:3.10.0"
}

protobuf {
    protoc {
        artifact = "com.google.protobuf:protoc:3.10.0"
    }

    generateProtoTasks {
        all().each { task ->
            task.builtins {
                java {
                    option 'lite'
                }
            }
        }
    }
}

Understanding std::apply inside std::visit

copy iconCopydownload iconDownload
(f = f, f = f, /*i == id*/ f = args.buildDefaultEffect(stack.getType()), f = f, f = f);
stack.addEffect(f);
-----------------------
((f = (i++ == id) ?
          args.template buildDefaultEffect<defaultEffect<decltype(stack.getType())>() : f), ...);
int i=0;
for...(auto& arg:args...){
  if (i!=id){
    ++i;
    continue;
  }
  f=arg.template buildDefaultEffect<defaultEffect<decltype(stack.getType())>();
  break;
}
((i++ == id) ?
          f=args.template buildDefaultEffect<defaultEffect<decltype(stack.getType())>() : nullptr), ...);
-----------------------
((f = (i++ == id) ?
          args.template buildDefaultEffect<defaultEffect<decltype(stack.getType())>() : f), ...);
int i=0;
for...(auto& arg:args...){
  if (i!=id){
    ++i;
    continue;
  }
  f=arg.template buildDefaultEffect<defaultEffect<decltype(stack.getType())>();
  break;
}
((i++ == id) ?
          f=args.template buildDefaultEffect<defaultEffect<decltype(stack.getType())>() : nullptr), ...);
-----------------------
((f = (i++ == id) ?
          args.template buildDefaultEffect<defaultEffect<decltype(stack.getType())>() : f), ...);
int i=0;
for...(auto& arg:args...){
  if (i!=id){
    ++i;
    continue;
  }
  f=arg.template buildDefaultEffect<defaultEffect<decltype(stack.getType())>();
  break;
}
((i++ == id) ?
          f=args.template buildDefaultEffect<defaultEffect<decltype(stack.getType())>() : nullptr), ...);

Field gets overwritten when opening audiostream in OBOE

copy iconCopydownload iconDownload
int sampleLengths[10] = { 0 };
-----------------------
vector<int> sampleLengths_;
sampleLengthsArrayLen_ = sampleLengthArrayLen;
sampleLengths_.assign(sampleLengths,sampleLengths+sampleLengthArrayLen);

Checking for undefined in if statements, leading to uncaught errors because item in if is undefined. What to do?

copy iconCopydownload iconDownload
if(item.image.filename in this)
if(!(item.image.filename in this))
-----------------------
if(item.image.filename in this)
if(!(item.image.filename in this))
-----------------------
if(typeof item !== 'object' || typeof item.image !== 'object' || item.image.filename === undefined){
  console.log("undefined as far as you're concerned");
}

C++, Android NDK: How to save my raw audio data to file properly and load it again

copy iconCopydownload iconDownload
bool Converter::doConversion(const std::string& fullPath, const std::string& name) {

    // here I'm setting up the extractor and necessary inputs. Omitted since not relevant

    // this is where the decoder is called to decode a file to raw audio
    constexpr int kMaxCompressionRatio{12};
    const long maximumDataSizeInBytes = kMaxCompressionRatio * (size) * sizeof(int16_t);
    auto decodedData = new uint8_t[maximumDataSizeInBytes];

    int64_t bytesDecoded = NDKExtractor::decode(*extractor, decodedData);
    auto numSamples = bytesDecoded / sizeof(int16_t);
 
    // converting to float has moved to the reading function, so now i save decodedData directly.

    std::string outputSuffix = ".pcm";
    std::string outputName = std::string(mFolder) + name + outputSuffix;
    std::ofstream outfile(outputName.c_str(), std::ios::out | std::ios::binary);
    
    outfile.write((char*)decodedData, numSamples * sizeof (int16_t));
    return true;
}
    long bufferSize;
    char * inputBuffer;

    std::ifstream stream;
    stream.open(fileName, std::ifstream::in | std::ifstream::binary);

    if (!stream.is_open()) {
        // handle error
    }

    stream.seekg (0, std::ios::end); // seek to the end
    bufferSize = stream.tellg(); // get size info, will be 0 without seeking to the end
    stream.seekg (0, std::ios::beg); // seek to beginning

    inputBuffer = new char [bufferSize];

    stream.read(inputBuffer, bufferSize); // the actual reading into the buffer. would be null without seeking back to the beginning
    stream.close();

    // done reading the file.
    
    auto numSamples = bufferSize / sizeof(int16_t); // calculate my number of samples, so the audio is correctly interpreted
    
    auto outputBuffer = std::make_unique<float[]>(numSamples);

    // the decoding bit now happens after the file is open. This avoids confusion
    // The NDK decoder can only decode to int16, we need to convert to floats
    oboe::convertPcm16ToFloat(
            reinterpret_cast<int16_t *>(inputBuffer),
            outputBuffer.get(),
            bufferSize / sizeof(int16_t));


    // here I continue working with my outputBuffer
-----------------------
bool Converter::doConversion(const std::string& fullPath, const std::string& name) {

    // here I'm setting up the extractor and necessary inputs. Omitted since not relevant

    // this is where the decoder is called to decode a file to raw audio
    constexpr int kMaxCompressionRatio{12};
    const long maximumDataSizeInBytes = kMaxCompressionRatio * (size) * sizeof(int16_t);
    auto decodedData = new uint8_t[maximumDataSizeInBytes];

    int64_t bytesDecoded = NDKExtractor::decode(*extractor, decodedData);
    auto numSamples = bytesDecoded / sizeof(int16_t);
 
    // converting to float has moved to the reading function, so now i save decodedData directly.

    std::string outputSuffix = ".pcm";
    std::string outputName = std::string(mFolder) + name + outputSuffix;
    std::ofstream outfile(outputName.c_str(), std::ios::out | std::ios::binary);
    
    outfile.write((char*)decodedData, numSamples * sizeof (int16_t));
    return true;
}
    long bufferSize;
    char * inputBuffer;

    std::ifstream stream;
    stream.open(fileName, std::ifstream::in | std::ifstream::binary);

    if (!stream.is_open()) {
        // handle error
    }

    stream.seekg (0, std::ios::end); // seek to the end
    bufferSize = stream.tellg(); // get size info, will be 0 without seeking to the end
    stream.seekg (0, std::ios::beg); // seek to beginning

    inputBuffer = new char [bufferSize];

    stream.read(inputBuffer, bufferSize); // the actual reading into the buffer. would be null without seeking back to the beginning
    stream.close();

    // done reading the file.
    
    auto numSamples = bufferSize / sizeof(int16_t); // calculate my number of samples, so the audio is correctly interpreted
    
    auto outputBuffer = std::make_unique<float[]>(numSamples);

    // the decoding bit now happens after the file is open. This avoids confusion
    // The NDK decoder can only decode to int16, we need to convert to floats
    oboe::convertPcm16ToFloat(
            reinterpret_cast<int16_t *>(inputBuffer),
            outputBuffer.get(),
            bufferSize / sizeof(int16_t));


    // here I continue working with my outputBuffer

Community Discussions

Trending Discussions on oboe
  • How can I call function with PointerByReference arguments for a Float[]?
  • Execution failed for task ':app:externalNativeBuildDebug' when using cpp and java in android
  • Oboe Systrace are non full buffers considered as underruns or not?
  • What is the best approach to stream JSON from a REST API to an Express app?
  • How do I avoid loops in R?
  • Oboe stops rendering audio if there is too many data to be rendered
  • How to handle speaker change with Android Oboe library?
  • How to pan audio sample data naturally?
  • How to add protobuf into flutter/kotlin android project
  • Understanding std::apply inside std::visit
Trending Discussions on oboe

QUESTION

How can I call function with PointerByReference arguments for a Float[]?

Asked 2021-Oct-21 at 15:21

I have a library that uses some c++ compiled code and I would like to use this and other functions to try it out but they all use Pointer and PointerByReference as arguments instead of normal types.

fun writeSampleFloat(length: Int,
                         leftOut: PointerByReference /*Float[]*/,
                         rightOut: PointerByReference/*Float[]*/)

I see it uses the JNA library but I cannot find how to get Pointer by reference of Float[] or Pointer of FloatArray or Pointer of ShortArray.

Ok So I am using instance of synth loaded in library project that uses jna, I would like record sound from it by using oboe example that I have in other library project but that uses jni. So basically everything works I can use synth and also oboe example can render sound from microphone and my idea to record that synth is to pass that instance of synth as native reference to that oboe cpp code so I can use render callback there to write data from synth. I can see how I can write data correctly but I don't know how to pass there instance. My first question was different becasue first idea was that I will call java form oboe rendering callback but because that is some realtime audio stuff this is no possible and worng approach I believe. so I would like to pass that synth I already have headers of synth in oboe included ...

So I have JNA val handle: PointerByReference in my kotlin/java project that references synth instance. I have also working jni access to oboe code like this :

 external fun create(): Boolean

that is defined in cpp like this:

Java_com_sheraz_oboerecorder_AudioEngine_create(JNIEnv *env, jobject obj)

can I pass that synth handle somehow so I can cast that handle of synth in cpp to actual type that i included in cpp and call that rendering function on it ?

I know probably best would be to write it all in jna but this cpp world is difficult for me. I just need to find a way to call that synth instance I see example how to write data from synth:

onAudioReady(AudioStream *stream, void *audioData, int32_t numFrames)
    {
    if(stream->getFormat() == AudioFormat::Float)
            {
                synth_write_float(dev->synth, numFrames, static_cast<float *>(audioData), 0, 2, static_cast<float *>(audioData), 1, 2);
            }
            else
            {
                synth_write_s16(dev->synth, numFrames, static_cast<short *>(audioData), 0, 2, static_cast<short *>(audioData), 1, 2);
            }
 return DataCallbackResult::Continue;
    }

This function I have it renders nicely audio from microphone and saves to file already. Now I have it like this

oboe::DataCallbackResult
RecordingCallback::onAudioReady(oboe::AudioStream *audioStream, void *audioData,
                                int32_t numFrames) {
   mSoundRecording->write(audioData, numFrames);
return oboe::DataCallbackResult::Continue;
}

I hope I can just pass there my JNA handle somehow and call that function on synth form audio rendering callback. This question starts to sound too complicated maybe it's another one.

ANSWER

Answered 2021-Oct-21 at 15:21

Since you don't include more of the API for a specific call I can't directly answer your implementation question, but I will address the portion of the question that asks about the types.

In C (and C++), arrays are stored in contiguous native memory. If you know the type (float in this case) you can simply offset from the pointer to get the appropriate element, e.g., foo[0] is at the pointer location to the array, foo[1] would be at that pointer location plus an offset equal to the type byte size (4 bytes for a float) and so on.

The Pointer and PointerByReference are JNA types. PointerByReference is a pointer that points to a Pointer; you can call the getValue() function on the PointerByReference() to retrieve this pointer.

Based on the way I read this API, that Pointer is actually the beginning of the float array, so you'd just use that Pointer and retrieve the array from its location.

So this is likely what you need to do:

length len = 123; // I assume you know this length

// call the function with your length

Pointer p = leftOut.getValue();
float[] leftArray = p.getFloatArray(0, len);

Pointer q = rightOut.getValue();
float[] rightArray = q.getFloatArray(0, len);

There may be a bit more to it, depending on whether the native float array memory is allocated by the API (in which case look for a function to release that memory) or whether you are required to allocate the native memory yourself, in which case you would do this:

// allocate memory for the float array of size len
Memory m = new Memory(4 * len);
// Memory extends pointer so just pass this to the PBR constructor
PointerByReference leftOut = new PointerByReference(m);
// now pass leftOut to the method

When using only JNA, you rarely need to deal with the actual native value of the pointer. However, in your edited question you seem to be wanting to interact with JNI code. In this case you'll want the pointer value to pass to those functions. It can be obtained with

long peer = Pointer.nativeValue(p); // or m or whatever the pointer is

Source https://stackoverflow.com/questions/69655516

Community Discussions, Code Snippets contain sources that include Stack Exchange Network

Vulnerabilities

No vulnerabilities reported

Install oboe

You can download it from GitHub.

Support

Getting Started GuideFull Guide to OboeAPI referenceTech NotesHistory of Audio features/bugs by Android versionMigration guide for apps using OpenSL ESFrequently Asked Questions (FAQ)Our roadmap - Vote on a feature/issue by adding a thumbs up to the first comment.

DOWNLOAD this Library from

Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
over 430 million Knowledge Items
Find more libraries
Reuse Solution Kits and Libraries Curated by Popular Use Cases

Save this library and start creating your kit

Share this Page

share link
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
over 430 million Knowledge Items
Find more libraries
Reuse Solution Kits and Libraries Curated by Popular Use Cases

Save this library and start creating your kit

  • © 2022 Open Weaver Inc.