-
Notifications
You must be signed in to change notification settings - Fork 120
/
sample_encoding.cpp
51 lines (38 loc) · 1.55 KB
/
sample_encoding.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
* Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <cstdio>
#include "pico/sample_conversion.h"
#include "pico/audio_spdif/sample_encoding.h"
#include "pico/audio_spdif.h"
#include "hardware/gpio.h"
static_assert(8 == sizeof(spdif_subframe_t), "");
// subframe within SPDIF
struct FmtSPDIF : public FmtDetails<spdif_subframe_t> {
};
template<typename FromFmt>
struct converting_copy<Stereo<FmtSPDIF>, Stereo<FromFmt>> {
static void copy(FmtSPDIF::sample_t *dest, const typename FromFmt::sample_t *src, uint sample_count) {
for (uint i = 0; i < sample_count * 2; i++) {
spdif_update_subframe(dest++, sample_converter<FmtS16 , FromFmt>::convert_sample(*src++));
}
}
};
template<typename FromFmt>
struct converting_copy<Stereo<FmtSPDIF>, Mono<FromFmt>> {
static void copy(FmtSPDIF::sample_t *dest, const typename FromFmt::sample_t *src, uint sample_count) {
for (uint i = 0; i < sample_count; i++) {
int16_t sample = sample_converter<FmtS16 ,FromFmt>::convert_sample(*src++);
spdif_update_subframe(dest++, sample);
spdif_update_subframe(dest++, sample);
}
}
};
void stereo_to_spdif_producer_give(audio_connection_t *connection, audio_buffer_t *buffer) {
producer_pool_blocking_give<Stereo<FmtSPDIF>, Stereo<FmtS16>>(connection, buffer);
}
void mono_to_spdif_producer_give(audio_connection_t *connection, audio_buffer_t *buffer) {
producer_pool_blocking_give<Stereo<FmtSPDIF>, Mono<FmtS16>>(connection, buffer);
}