circuitpython/shared-module/synthio/MidiTrack.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

32 lines
965 B
C

// This file is part of the CircuitPython project: https://circuitpython.org
//
// SPDX-FileCopyrightText: Copyright (c) 2021 Artyom Skrobov
//
// SPDX-License-Identifier: MIT
#pragma once
#include "py/obj.h"
#include "shared-module/synthio/__init__.h"
typedef struct {
synthio_synth_t synth;
mp_buffer_info_t track;
// invariant: after initial startup, pos always points just after an encoded duration, i.e., at a midi message (or at EOF)
size_t pos;
mp_int_t error_location;
uint32_t tempo;
} synthio_miditrack_obj_t;
// These are not available from Python because it may be called in an interrupt.
void synthio_miditrack_reset_buffer(synthio_miditrack_obj_t *self,
bool single_channel_output,
uint8_t channel);
audioio_get_buffer_result_t synthio_miditrack_get_buffer(synthio_miditrack_obj_t *self,
bool single_channel_output,
uint8_t channel,
uint8_t **buffer,
uint32_t *buffer_length); // length in bytes