GithubHelp home page GithubHelp logo

Comments (9)

ekuleshov avatar ekuleshov commented on June 1, 2024

@EliaTolin you should be able to connect the FftNode from coast_audio_fft into the audio graph as used in the audio_recorder' example. That will give you the FFT data for a given audio data buffer. The music_playerdoes that for selected audio file and shows the result withFftView` widget.

@SKKbySSK though I could not figure out how to process audio data without having EncoderNode or something like MabPlaybackDeviceNode at the end of the audio graph.

Also it is somewhat cumbersome to get the audio position from within processor nodes, such as FftNode. You have to go all the way to decoder to get the position, as MabAudioPlayer.position method does. It would be really handy if ProcessorNodeMixin.process() method also had the AudioTime parameter along with the AudioBuffer.

from coast_audio.

SKKbySSK avatar SKKbySSK commented on June 1, 2024

@ekuleshov
Sorry for my late response.

I could not figure out how to process audio data without having EncoderNode or something like MabPlaybackDeviceNode at the end of the audio graph.

Most of nodes have one outputBus and it has read function to process audio data.
So, you should be able to do that something like this.

final graphNode = GraphNode();
final sineNode = FunctionNode(function: const SineFunction(), format: format, frequency: freq);
final sineVolumeNode = VolumeNode(volume: 0.2);

graphNode.connect(sineNode.outputBus, sineVolumeNode.inputBus);
graphNode.connectEndpoint(sineVolumeNode.outputBus);

// Allocate 10 seconds audio buffer.
final frames = AllocatedAudioFrames(
  length: format.sampleRate * 10,
  format: format,
);

frames.acquireBuffer((buffer) {
  // Read the graph's output data
  final framesRead = graphNode.outputBus.read(buffer);
  final readBuffer = buffer.limit(framesRead);

  // do something on readBuffer
});

from coast_audio.

SKKbySSK avatar SKKbySSK commented on June 1, 2024

Also it is somewhat cumbersome to get the audio position from within processor nodes, such as FftNode. You have to go all the way to decoder to get the position, as MabAudioPlayer.position method does. It would be really handy if ProcessorNodeMixin.process() method also had the AudioTime parameter along with the AudioBuffer.

Since position has different implications depending on the context and the processor node has responsible for processing audio data, not for calculating position, I don't think it is a good solution.

from coast_audio.

ekuleshov avatar ekuleshov commented on June 1, 2024

Also it is somewhat cumbersome to get the audio position from within processor nodes, such as FftNode. You have to go all the way to decoder to get the position, as MabAudioPlayer.position method does. It would be really handy if ProcessorNodeMixin.process() method also had the AudioTime parameter along with the AudioBuffer.

Since position has different implications depending on the context and the processor node has responsible for processing audio data, not for calculating position, I don't think it is a good solution.

Thank you for these pointers. But will that work, for example, with FftNode? And I'm still unclear how to link the audio position with result of processing, e.g. use FftCompletedCallback data to create an audio spectrogram similar to this.

image

from coast_audio.

SKKbySSK avatar SKKbySSK commented on June 1, 2024

FftResult has frames and format properties.
So, you can calculate the duration of the result like this.

FftResult result;
final durationSeconds = AudioTime.fromFrames(frames: result.frames, format: result.format).seconds;

And you should sum it in each callback.

var positionSeconds = 0.0;
FftNode(
  ...
  onFftCompleted: (result) {
    positionSeconds += AudioTime.fromFrames(frames: result.frames, format: result.format).seconds;
  },
);

from coast_audio.

ekuleshov avatar ekuleshov commented on June 1, 2024

FftResult has frames and format properties. So, you can calculate the duration of the result like this... And you should sum it in each callback.

Unfortunately this approach does not work when upstream node rolled back position in the audio stream. E.g. when FftNode (only using it as an example) is hooked up in the music player and user rewinds the audio, that summed up position won't be correct anymore. I suppose I could also subscribe to that rewind event, but that is even more cumbersome.

from coast_audio.

ekuleshov avatar ekuleshov commented on June 1, 2024
final framesRead = graphNode.outputBus.read(buffer);

@SKKbySSK in the above snippet it only reads up to the allocated 10 sec buffer out of the graphNode.outputBus.
But how can I continuously read the entire decoded audio stream, say in chunks of 256 frames?

from coast_audio.

github-actions avatar github-actions commented on June 1, 2024

This issue is stale because it has been open for 30 days with no activity.

from coast_audio.

github-actions avatar github-actions commented on June 1, 2024

This issue was closed because it has been inactive for 7 days since being marked as stale.

from coast_audio.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.