Comments (6)
from flutter_soloud.
Hi @themailman05,
I reviewed the code a bit because it's been a while since i wrote that.
You are right, the getCaptureAudioTexture2d
is the only function exposed here. It takes the first 256 floats of the captured buffer samples and use them to calculate the FFT returning one 2D array where each row (512 floats) is represented by 256 floats of FFT data and 256 float with wave data.
So you can use just the 2nd 256 floats of the first row (which is the latest data). But as said before, the buffer is 1024. You will lose the other 768 floats.
It was planned to add a function to get all the buffer, but some testing are needed.
The way to proceed:
- the miniaudio callback fills and replaces data of the buffer every time is called
- the miniaudio callback must not do anything expensive
- write a C function to get the buffer and its Dart binding
The problem:
from Dart, after calling the get buffer method, you are supposed to do something with that data. Meanwhile the miniaudio callback might have been called many times and so you will lose those new buffer data.
I don't know how to solve this if it is a real problem, losing some data from the mic could't be a problem in most cases. My thoughts is to write a temp file or a buffer that decrease when requesting data (and increases when the miniaudio callback is called).
If you want to contribute in some way that would be great!! I'm terrible at writing docs, some guys told me they were scared reading it! :)
Anyway, In this week end I'll try to do something. Let me know.
Thanks
from flutter_soloud.
Tinkering with it a bit this weekend. I tried just refactoring the getAudioTexture2D but without printf
statements showing up I am having a hard time debugging the C++ side. Any tips for getting debug printing to display? Would help a great deal.
from flutter_soloud.
On Android the printf doesn't output on console as you noticed. It has its own log like __android_log_vprint()
. I have written a common platform_log()
in common.h which should work but I didn't tested well on other platforms.
If you are using VS Code you could also debug C/C++ code. I set up the run actions in .vscode/launch.json
for linux and windows, but you should install C/C++ Extension Pack
and C/C++ for Visual Studio Code
by Microsoft.
To debug C/C++ code with Android Studio, you should open the android
folder project and edit the run configuration to use native debug.
from flutter_soloud.
Some times ago I did already a circular buffer class. Feel free to use it
circular_buffer.h
#ifndef CIRCULAR_BUFFER_H
#define CIRCULAR_BUFFER_H
#include <iostream>
#include <vector>
#include <algorithm>
class CircularBuffer {
private:
std::vector<float> buffer;
size_t maxSize;
size_t currentSize;
size_t head;
size_t tail;
public:
explicit CircularBuffer(size_t size) : buffer(size), maxSize(size), currentSize(0), head(0), tail(0) {}
int size() {return currentSize;}
void push(const std::vector<float>& values) {
size_t numValues = values.size();
// Check if the buffer is full
if (currentSize + numValues > maxSize) {
size_t numToRemove = currentSize + numValues - maxSize;
head = (head + numToRemove) % maxSize;
currentSize -= numToRemove;
}
size_t numTail = std::min(numValues, maxSize - tail);
// Copy values to the tail of the buffer
std::copy(values.begin(), values.begin() + numTail, buffer.begin() + tail);
// If there are remaining values, copy them to the head of the buffer
if (numValues > numTail) {
std::copy(values.begin() + numTail, values.end(), buffer.begin());
}
tail = (tail + numValues) % maxSize;
currentSize = std::min(currentSize + numValues, maxSize);
}
std::vector<float> pop(size_t numValues) {
numValues = std::min(numValues, currentSize);
std::vector<float> poppedValues(numValues);
size_t numTail = std::min(numValues, maxSize - head);
// Copy values from the head of the buffer
std::copy(buffer.begin() + head, buffer.begin() + head + numTail, poppedValues.begin());
// If there are remaining values, copy them from the tail of the buffer
if (numValues > numTail) {
std::copy(buffer.begin(), buffer.begin() + numValues - numTail, poppedValues.begin() + numTail);
}
head = (head + numValues) % maxSize;
currentSize -= numValues;
return poppedValues;
}
void print() const {
std::cout << "N: " << currentSize << " - ";
for (size_t i = 0; i < currentSize; ++i) {
size_t index = (head + i) % maxSize;
std::cout << buffer[index] << " ";
}
std::cout << std::endl;
}
};
#endif // CIRCULAR_BUFFER_H
from flutter_soloud.
Hello,
I have made some progress on audio capture to buffer, but having some trouble with formats.
As I understand it the void* pInput
incoming to data_callback
is an interleaved 2-channel float32 buffer.
I am using memcpy in the callback to write to a preallocated buffer.
I am now working on exposing the SoLoud Wav loadMem bindings as function calls as well.
I think actually I need to use SoLoud Wav loadRawWave for the float pcm buffer that is emitted from the capture callback. I am still learning miniaudio so please let me know if I am on the right track. I'm happy to contribute back what I build once I get the kinks worked out.
from flutter_soloud.
Related Issues (20)
- Windows compilation HOT 3
- More pub.dev points HOT 2
- Readme add a quick link to pub.dev HOT 3
- App getting crashed without throwing any error HOT 5
- fix: building on linux fails HOT 1
- fix: same audio gets repeat again while playing from URL HOT 2
- feat: I want to change the color from red to white. HOT 5
- docs: How to get value of frequencies? HOT 3
- How I can change opacity of the red lines and set pitch HOT 3
- fix: Building project using Linux does not build the app HOT 2
- fix: A constant stream of messages in console HOT 12
- Cannot find how to play recorded sound HOT 3
- fix: A lot of RAM is needed HOT 3
- docs: How to get getAudioTexture in specific time? HOT 1
- How to get onsets and pitches? HOT 3
- feat: Add custom source data for capturing HOT 3
- flutter_localizations version conflict HOT 1
- I get "Redefinition of catmullrom" every time i try to run the example app HOT 3
- Play and seek multiple sounds at the same time. HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
š Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ššš
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ā¤ļø Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flutter_soloud.