android audiomixer,GitHub - Piasy/AudioMixer: A cross-platform audio mixer, supports Android, iOS, m...

AudioMixer

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

Install

Android

68747470733a2f2f6170692e62696e747261792e636f6d2f7061636b616765732f70696173792f6d6176656e2f417564696f4d697865722f696d616765732f646f776e6c6f61642e737667

allprojects {

repositories {

maven {

url "http://dl.bintray.com/piasy/maven"

}

}

}

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

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:

mixer.addRecordedData(2, 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

[PYAAudioMixer globalInitializeFFmpeg];

Create mixer:

#import

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:

[_mixer addRecordedData:2 data:_buffer size:mixerInputSize];

_mixedBuffer = [_mixer mix];

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值