Git Product home page Git Product logo

audiomixer's Introduction

AudioMixer

A cross-platform audio mixer, supports Android, iOS, macOS and Windows. Powered by WebRTC, FFmpeg and Djinni.

Install

Android

Download

allprojects {
    repositories {
        maven {
            url  "http://dl.bintray.com/piasy/maven"
        }
    }
}

compile 'com.github.piasy:AudioMixer:1.0.1'

iOS & macOS

Due to the file size limitation, publish with CocoaPods is difficult, so please download the prebuilt AudioMixer.framework directly.

Usage

Android

Initialize:

AudioMixer.globalInitialize();

Create mixer:

AudioMixer mixer = new AudioMixer(new MixerConfig(
        new ArrayList<>(Arrays.asList(
                new MixerSource(MixerSource.TYPE_FILE, 1, 1,
                        "/sdcard/mp3/morning.mp3", 0, 0),
                new MixerSource(MixerSource.TYPE_RECORD, 2, 1, "", sampleRate,
                        channelNum)
        )),
        sampleRate, channelNum, frameDurationMs
));

Do mix with recorded data:

AudioBuffer buffer = mixer.addRecordedDataAndMix(buf, size);

Do mix with file only:

AudioBuffer buffer = mixer.mix();

Use the mixed audio data:

if (buffer.getSize() > 0) {
    audioTrack.write(buffer.getBuffer(), 0, buffer.getSize());
}

For more detailed info, please refer to the source code.

iOS & macOS

Initialize:

#import <AudioMixer/AudioMixer.h>

[PYAAudioMixer globalInitializeFFmpeg];

Create mixer:

#import <AudioMixer/AudioMixer.h>

NSArray* mixerSources = @[
    [PYAMixerSource
        mixerSourceWithType:PYAMixerSourceTypeFile
                       ssrc:1
                     volume:1
                       path:[self pathForFileName:@"morning.mp3"]
                 sampleRate:0
                 channelNum:0],
    [PYAMixerSource mixerSourceWithType:PYAMixerSourceTypeRecord
                                   ssrc:2
                                 volume:1
                                   path:@""
                             sampleRate:_sampleRate
                             channelNum:_channelNum],
];
PYAMixerConfig* config = [PYAMixerConfig mixerConfigWithSources:mixerSources
                                               outputSampleRate:_sampleRate
                                               outputChannelNum:_channelNum
                                                frameDurationMs:10];
_mixer = [[PYAAudioMixer alloc] initWithConfig:config];

Do mix with recorded data:

_mixedBuffer = [_mixer addRecordedDataAndMix:_buffer size:mixerInputSize];

Do mix with file only:

_mixedBuffer = [_mixer mix];

Use the mixed audio data:

if (_mixedBuffer.size > 0) {
  write([_recordAndMixDumper fileDescriptor], _mixedBuffer.data,
        _mixedBuffer.size);
}

For more detailed info, please refer to the source code.

Dependencies

  • FFmpeg: 3.4.2
  • WebRTC: #23794

Development

  • Before run Android demo, push mp3 to sdcard: adb push mp3 /sdcard/
  • Generate sources: ./run_djinni.sh
  • Extract libs: ./extract_libs.sh

Caveat

  • Due to the limitation of WebRTC, frameDurationMs must be 10ms, and we must mix 10ms's audio data each time;

TODO

  • ffmpeg 4.0 audio decoder doesn't work
  • iOS
  • macOS
  • Windows

audiomixer's People

Contributors

piasy avatar

Watchers

 avatar

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.