SAF
Loading...
Searching...
No Matches
tvconv_internal.c
Go to the documentation of this file.
1/*
2 * Copyright 2020 Leo McCormack
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
9 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
10 * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
11 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
13 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14 * PERFORMANCE OF THIS SOFTWARE.
15 */
16
24#include "tvconv_internal.h"
25
26void tvconv_setCodecStatus(void* const hTVCnv, CODEC_STATUS newStatus)
27{
28 tvconv_data *pData = (tvconv_data*)(hTVCnv);
29 if(newStatus==CODEC_STATUS_NOT_INITIALISED){
30 /* Pause until current initialisation is complete */
31 while(pData->codecStatus == CODEC_STATUS_INITIALISING)
32 SAF_SLEEP(10);
33 }
34 pData->codecStatus = newStatus;
35}
36
37void tvconv_findNearestNeigbour(void* const hTVCnv)
38{
39 float dist = 0, minDist = 0;
40 int i, d, min_idx = 0;
41 tvconv_data *pData = (tvconv_data*)(hTVCnv);
42 if (pData->nListenerPositions > 0 && pData->listenerPositions != NULL) {
43 for(i = 0; i < pData->nListenerPositions; i++){
44 for(d = 0; d < NUM_DIMENSIONS; d++)
45 dist += (pData->targetPosition[d] - pData->listenerPositions[i][d]) *
46 (pData->targetPosition[d] - pData->listenerPositions[i][d]);
47
48 if(dist < minDist || i == 0){
49 minDist = dist;
50 min_idx = i;
51 }
52 dist = 0;
53 }
54 }
55
56 pData->position_idx = min_idx;
57}
58
59void tvconv_setMinMaxDimensions(void* const hTVCnv)
60{
61 int i, d;
62 tvconv_data *pData = (tvconv_data*)(hTVCnv);
63 if(pData->listenerPositions != NULL){
64 for(d = 0; d < NUM_DIMENSIONS; d++){
65 pData->minDimensions[d] = pData->listenerPositions[0][d];
66 pData->maxDimensions[d] = pData->listenerPositions[0][d];
67 for(i = 1; i<pData->nListenerPositions; i++){
68 if(pData->listenerPositions[i][d] < pData->minDimensions[d])
69 pData->minDimensions[d] = pData->listenerPositions[i][d];
70 else if (pData->listenerPositions[i][d] > pData->maxDimensions[d])
71 pData->maxDimensions[d] = pData->listenerPositions[i][d];
72 }
73 }
74 /* resetting current position to the start */
75 for(d = 0; d < NUM_DIMENSIONS; d++)
76 pData->targetPosition[d] = pData->minDimensions[d];
77 }
78}
CODEC_STATUS
Current status of the codec.
Definition _common.h:201
@ CODEC_STATUS_NOT_INITIALISED
Codec has not yet been initialised, or the codec configuration has changed.
Definition _common.h:204
@ CODEC_STATUS_INITIALISING
Codec is currently being initialised, input audio should not be processed.
Definition _common.h:207
Main structure for tvconv
vectorND minDimensions
Minimum values across all dimensions.
vectorND maxDimensions
Maximum values across all dimensions.
vectorND * listenerPositions
The listener positions; nListenerPositions x 3.
void tvconv_findNearestNeigbour(void *const hTVCnv)
Finds the index holding the nearest neigbour to the selected position.
void tvconv_setCodecStatus(void *const hTVCnv, CODEC_STATUS newStatus)
Sets codec status (see CODEC_STATUS enum)
void tvconv_setMinMaxDimensions(void *const hTVCnv)
Sets the smallest and the highest position of each dimension from the list of positions.
A time-varying multi-channel convolver.