circuitpython/shared-module/audiomixer/Mixer.h
Jeff Epler e15eba0d33 audio: reduce code size
By placing certain fields in a fixed location in all sample types,
code can be reduced & reused. For instance, the same property object
can be used for every sample type's `sample_rate` property.

The sample proto functions like `sample_rate` become superfluous since
once an object is verified to support the audiosample protocol, direct
access to the fields in the base object is possible.
2025-02-06 21:56:09 -06:00

39 lines
1.1 KiB
C

// This file is part of the CircuitPython project: https://circuitpython.org
//
// SPDX-FileCopyrightText: Copyright (c) 2018 Scott Shawcroft
//
// SPDX-License-Identifier: MIT
#pragma once
#include "py/obj.h"
#include "py/objtuple.h"
#include "shared-module/audiocore/__init__.h"
typedef struct {
audiosample_base_t base;
uint32_t *first_buffer;
uint32_t *second_buffer;
uint32_t len; // in words
bool use_first_buffer;
uint32_t read_count;
uint32_t left_read_count;
uint32_t right_read_count;
uint8_t voice_count;
mp_obj_tuple_t *voice_tuple;
mp_obj_t voice[];
} audiomixer_mixer_obj_t;
// These are not available from Python because it may be called in an interrupt.
void audiomixer_mixer_reset_buffer(audiomixer_mixer_obj_t *self,
bool single_channel_output,
uint8_t channel);
audioio_get_buffer_result_t audiomixer_mixer_get_buffer(audiomixer_mixer_obj_t *self,
bool single_channel_output,
uint8_t channel,
uint8_t **buffer,
uint32_t *buffer_length); // length in bytes