2017-03-31 13:03:38 +09:00
|
|
|
#include "audio-repack.h"
|
|
|
|
|
2019-10-09 16:13:23 +00:00
|
|
|
#include <util/sse-intrin.h>
|
2017-03-31 13:03:38 +09:00
|
|
|
|
|
|
|
int check_buffer(struct audio_repack *repack, uint32_t frame_count)
|
|
|
|
{
|
|
|
|
const uint32_t new_size =
|
|
|
|
frame_count * repack->base_dst_size + repack->extra_dst_size;
|
|
|
|
|
|
|
|
if (repack->packet_size < new_size) {
|
|
|
|
repack->packet_buffer =
|
|
|
|
brealloc(repack->packet_buffer, new_size);
|
|
|
|
if (!repack->packet_buffer)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
repack->packet_size = new_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2018-06-28 02:11:15 +02:00
|
|
|
* Squash arrays.
|
|
|
|
* For instance:
|
2017-12-05 00:26:47 +01:00
|
|
|
* 2.1:
|
|
|
|
*
|
|
|
|
* | FL | FR | LFE | emp | emp | emp |emp |emp |
|
|
|
|
* | | |
|
|
|
|
* | FL | FR | LFE |
|
2018-06-28 02:11:15 +02:00
|
|
|
*/
|
2017-03-31 13:03:38 +09:00
|
|
|
|
2018-06-28 02:11:15 +02:00
|
|
|
int repack_squash(struct audio_repack *repack, const uint8_t *bsrc,
|
2017-03-31 13:03:38 +09:00
|
|
|
uint32_t frame_count)
|
|
|
|
{
|
|
|
|
if (check_buffer(repack, frame_count) < 0)
|
|
|
|
return -1;
|
|
|
|
|
libobs: Add surround sound audio support
(This commit also modifies the following modules: UI,
deps/media-playback, coreaudio-encoder, decklink, linux-alsa,
linux-pulseaudio, mac-capture, obs-ffmpeg, obs-filters, obs-libfdk,
obs-outputs, win-dshow, and win-wasapi)
Adds surround sound audio support to the core, core plugins, and user
interface.
Compatible streaming services: Twitch, FB 360 live
Compatible protocols: rtmp / mpeg-ts tcp udp
Compatible file formats: mkv mp4 ts (others untested)
Compatible codecs: ffmpeg aac, fdk_aac, CoreAudio aac,
opus, vorbis, pcm (others untested).
Tested streaming servers: wowza, nginx
HLS, mpeg-dash : surround passthrough
Html5 players tested with live surround:
videojs, mediaelement, viblast (hls+dash), hls.js
Decklink: on win32, swap channels order for 5.1 7.1
(due to different channel mapping on wav, mpeg, ffmpeg)
Audio filters: surround working.
Monitoring: surround working (win macOs linux (pulse-audio)).
VST: stereo plugins keep in general only the first two channels.
surround plugins should work (e.g. mcfx does).
OS: win, macOs, linux (alsa, pulse-audio).
Misc: larger audio bitrates unlocked to accommodate more channels
NB: mf-aac only supports mono and stereo + 5.1 on win 10
(not implemented due to lack of usefulness)
Closes jp9000/obs-studio#968
2017-05-27 02:15:54 +02:00
|
|
|
int squash = repack->extra_dst_size;
|
2017-03-31 13:03:38 +09:00
|
|
|
const __m128i *src = (__m128i *)bsrc;
|
|
|
|
const __m128i *esrc = src + frame_count;
|
libobs: Add surround sound audio support
(This commit also modifies the following modules: UI,
deps/media-playback, coreaudio-encoder, decklink, linux-alsa,
linux-pulseaudio, mac-capture, obs-ffmpeg, obs-filters, obs-libfdk,
obs-outputs, win-dshow, and win-wasapi)
Adds surround sound audio support to the core, core plugins, and user
interface.
Compatible streaming services: Twitch, FB 360 live
Compatible protocols: rtmp / mpeg-ts tcp udp
Compatible file formats: mkv mp4 ts (others untested)
Compatible codecs: ffmpeg aac, fdk_aac, CoreAudio aac,
opus, vorbis, pcm (others untested).
Tested streaming servers: wowza, nginx
HLS, mpeg-dash : surround passthrough
Html5 players tested with live surround:
videojs, mediaelement, viblast (hls+dash), hls.js
Decklink: on win32, swap channels order for 5.1 7.1
(due to different channel mapping on wav, mpeg, ffmpeg)
Audio filters: surround working.
Monitoring: surround working (win macOs linux (pulse-audio)).
VST: stereo plugins keep in general only the first two channels.
surround plugins should work (e.g. mcfx does).
OS: win, macOs, linux (alsa, pulse-audio).
Misc: larger audio bitrates unlocked to accommodate more channels
NB: mf-aac only supports mono and stereo + 5.1 on win 10
(not implemented due to lack of usefulness)
Closes jp9000/obs-studio#968
2017-05-27 02:15:54 +02:00
|
|
|
uint16_t *dst = (uint16_t *)repack->packet_buffer;
|
2018-06-28 02:11:15 +02:00
|
|
|
|
|
|
|
/* Audio needs squashing in order to avoid resampling issues.
|
2019-03-01 09:59:58 +01:00
|
|
|
* The condition checks for 7.1 audio for which no squash is needed.
|
2017-12-05 00:26:47 +01:00
|
|
|
*/
|
2019-03-01 09:59:58 +01:00
|
|
|
if (squash > 0) {
|
|
|
|
while (src != esrc) {
|
|
|
|
__m128i target = _mm_load_si128(src++);
|
|
|
|
_mm_storeu_si128((__m128i *)dst, target);
|
|
|
|
dst += 8 - squash;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int repack_squash_swap(struct audio_repack *repack, const uint8_t *bsrc,
|
|
|
|
uint32_t frame_count)
|
|
|
|
{
|
|
|
|
if (check_buffer(repack, frame_count) < 0)
|
|
|
|
return -1;
|
|
|
|
int squash = repack->extra_dst_size;
|
|
|
|
const __m128i *src = (__m128i *)bsrc;
|
|
|
|
const __m128i *esrc = src + frame_count;
|
|
|
|
uint16_t *dst = (uint16_t *)repack->packet_buffer;
|
2018-06-28 02:11:15 +02:00
|
|
|
while (src != esrc) {
|
|
|
|
__m128i target = _mm_load_si128(src++);
|
2019-03-01 09:59:58 +01:00
|
|
|
__m128i buf =
|
|
|
|
_mm_shufflelo_epi16(target, _MM_SHUFFLE(2, 3, 1, 0));
|
|
|
|
_mm_storeu_si128((__m128i *)dst, buf);
|
2018-06-28 02:11:15 +02:00
|
|
|
dst += 8 - squash;
|
2017-03-31 13:03:38 +09:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int audio_repack_init(struct audio_repack *repack,
|
|
|
|
audio_repack_mode_t repack_mode, uint8_t sample_bit)
|
|
|
|
{
|
|
|
|
memset(repack, 0, sizeof(*repack));
|
|
|
|
|
|
|
|
if (sample_bit != 16)
|
|
|
|
return -1;
|
2019-03-01 09:59:58 +01:00
|
|
|
int _audio_repack_ch[8] = {3, 4, 5, 6, 5, 6, 8, 8};
|
2018-06-28 02:11:15 +02:00
|
|
|
repack->base_src_size = 8 * (16 / 8);
|
2019-03-01 09:59:58 +01:00
|
|
|
repack->base_dst_size = _audio_repack_ch[repack_mode] * (16 / 8);
|
|
|
|
repack->extra_dst_size = 8 - _audio_repack_ch[repack_mode];
|
2018-06-28 02:11:15 +02:00
|
|
|
repack->repack_func = &repack_squash;
|
2019-03-01 09:59:58 +01:00
|
|
|
if (repack_mode == repack_mode_8to5ch_swap ||
|
|
|
|
repack_mode == repack_mode_8to6ch_swap ||
|
|
|
|
repack_mode == repack_mode_8ch_swap)
|
|
|
|
repack->repack_func = &repack_squash_swap;
|
2017-03-31 13:03:38 +09:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void audio_repack_free(struct audio_repack *repack)
|
|
|
|
{
|
|
|
|
if (repack->packet_buffer)
|
|
|
|
bfree(repack->packet_buffer);
|
|
|
|
|
|
|
|
memset(repack, 0, sizeof(*repack));
|
|
|
|
}
|