2019-08-03 12:20:06 -04:00
|
|
|
/*
|
|
|
|
* This file is part of the Micro Python project, http://micropython.org/
|
|
|
|
*
|
|
|
|
* The MIT License (MIT)
|
|
|
|
*
|
|
|
|
* Copyright (c) 2018 DeanM for Adafruit Industries
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
2019-08-25 00:36:18 -04:00
|
|
|
#ifndef SHARED_MODULE_AUDIOMIXER_MIXERVOICE_H_
|
|
|
|
#define SHARED_MODULE_AUDIOMIXER_MIXERVOICE_H_
|
2019-08-03 12:20:06 -04:00
|
|
|
|
|
|
|
#include "py/obj.h"
|
|
|
|
|
2019-08-25 00:36:18 -04:00
|
|
|
#include "shared-module/audiomixer/__init__.h"
|
|
|
|
#include "shared-module/audiomixer/Mixer.h"
|
2019-08-03 12:20:06 -04:00
|
|
|
|
|
|
|
typedef struct {
|
2021-03-15 09:57:36 -04:00
|
|
|
mp_obj_base_t base;
|
|
|
|
audiomixer_mixer_obj_t *parent;
|
2019-08-03 12:20:06 -04:00
|
|
|
mp_obj_t sample;
|
|
|
|
bool loop;
|
|
|
|
bool more_data;
|
2021-03-15 09:57:36 -04:00
|
|
|
uint32_t *remaining_buffer;
|
2019-08-03 12:20:06 -04:00
|
|
|
uint32_t buffer_length;
|
Mixer: Rework for performance, particularly of the S16 case
This removes downscaling (halving-add) when multiple voices are
being mixed. To avoid clipping, and get similar behavior to before,
set the "level" of each voice to (1/voice_count).
Slow paths that were applicable to only M0 chips were removed.
As a side effect, the internal volume representation is now 0 ..
0x8000 (inclusive), which additionally makes a level of exactly 0.5
representable.
Testing performed, on PyGamer: For all 4 data cases, for stereo and
mono, for 1 and 2 voices, play pure sign waves represented as
RawSamples and view the result on a scope and through headphones.
Also, scope the amount of time spent in background tasks.
Code size: growth of +272 bytes
Performance (time in background task when mixing 2 stereo 16-bit voices):
76us per down from 135us (once per ~2.9ms long term average)
(Decrease from 4.7% to 2.4% of all CPU time)
2020-01-12 12:02:47 -05:00
|
|
|
uint16_t level;
|
2019-08-25 00:36:18 -04:00
|
|
|
} audiomixer_mixervoice_obj_t;
|
2019-08-03 12:20:06 -04:00
|
|
|
|
|
|
|
|
2019-08-25 00:36:18 -04:00
|
|
|
#endif /* SHARED_MODULE_AUDIOMIXER_MIXERVOICE_H_ */
|