SpiritLdCtrl UG PDF
SpiritLdCtrl UG PDF
User's Guide
Version 1.0
October, 2010
Copyright Information
© 2011, SPIRIT. All rights reserved.
This document is protected by copyright. No part of this document may be reproduced in any form by any
means without prior written authorization of SPIRIT.
Contents
1. INTRODUCTION ..................................................................................................................... 5
1.1. Product overview ..................................................................................................................... 5
1.2. Related products ..................................................................................................................... 5
1.3. Document Overview ................................................................................................................ 5
2. FUNCTIONAL DESCRIPTION ................................................................................................ 6
2.1. Algorithm overview .................................................................................................................. 6
2.2. Features and recommendations on loudness control usage .................................................. 8
3. API DESCRIPTION ................................................................................................................. 9
3.1. Integration flow ........................................................................................................................ 9
3.2. Predefined constants ............................................................................................................... 9
3.3. TSpiritLdCtrl ............................................................................................................................ 9
3.4. TSpiritLdCtrl_Prms .................................................................................................................. 9
3.5. SpiritLdCtrl_Init () .................................................................................................................. 10
3.6. SpiritLdCtrl_Reset () .............................................................................................................. 10
3.7. SpiritLdCtrl_SetPrms () ......................................................................................................... 11
3.8. SpiritLdCtrl_GetPrms () ......................................................................................................... 11
3.9. SpiritLdCtrl_Apply () .............................................................................................................. 12
3.10. Error codes ............................................................................................................................ 12
3.11. Application example .............................................................................................................. 13
1. Introduction
The purpose of this document is to describe API, integration process and test procedures of Loudness
control software.
Sampling rate 8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000 Hz
Input and output signal format Interleaved, linear 16-bit PCM, little-endian format.
Table 1 Specifications
For more information about other SPIRIT audio processing technologies visit www.spiritDSP.com.
SPIRIT reserves the right to make changes to its products to improve the products’ technical
characteristics without any notice. Customers are advised to obtain the latest version of relevant information
to verify that the data is up-to-date before placing the orders.
SPIRIT warrants performance of its products to current specifications in accordance with SPIRIT's
standard warranty. Testing and other quality control techniques are utilized to the extent deemed necessary
to support this warranty.
2. Functional Description
This section describes loudness control algorithm and provides several recommendations on its usage.
Now, consider the equal loudness contour dependency on SPL. More precisely, let references SPL is 40
dB and test signals are two pure tones f0 and f1 with magnitude level corresponding to 40 Ph level; listener
can’t determine the difference in their loudness. Amplify test vectors with a given gain. They becomes at a
different loudness level, it means they perceived as different volume signals. This difference can be
expressed in phons:
†
See ISO 226:1987 (E), standardized frequency range [20, 12500] Hz
Assumes f 0 is fixed at 1kHz, the correction which should be introduced after linear scaling to move
signal to a Ph( A f 0 _ dB gain _ dB) level is shown on Figure 2.
Amplifier
Main processing Loudness control output
(analog or digital)
gain/system_unity_gain
By default, acceptable gain range is [-36, +36] dB. This range may be too wide for most of devices. One
can reduce this range just feeding scaled gain value to loudness control unit. For example, the multiplication
of input gain by 2 constricts acceptable gain range to [-30, 30] dB interval.
3. API description
This section describes software implementation and its interface.
3.3. TSpiritLdCtrl
Syntax
Remarks
Alias of the persistent memory buffer. Only a pointer on this type has sense; all API functions expect it
points to a 4 bytes aligned memory region.
3.4. TSpiritLdCtrl_Prms
Syntax
typedef struct {
int gainQ8;
} TSpiritLdCtrl_Prms;
Members
gainQ8 Amplifier gain in Q8 format in range [SPIRIT_LDCTRL_GAIN_MIN,
SPIRIT_LDCTRL_GAIN_MAX]
Remarks
This structure carries run-time software parameters. Note that unity gain value in Q8 format is equal to
(1<< SPIRIT_LDCTRL_GAIN_Q_BITS).
3.5. SpiritLdCtrl_Init ()
Syntax
int SpiritLdCtrl_Init (
const TSpiritLdCtrl *ld,
unsigned long sampleRateHz
);
Parameters
ld Pointer to persistent memory buffer.
sampleRateHz Sampling rate in Hz. Must be positive integer number.
Return value
Error code.
Remarks
This function initializes loudness control persistent memory buffer and resets filters delay.
3.6. SpiritLdCtrl_Reset ()
Syntax
int SpiritLdCtrl_Reset (
const TSpiritLdCtrl *ld
);
Parameters
ld Pointer to initialized persistent memory buffer.
Return value
Error code.
Remarks
This function resets loudness control state:
- Set filter delay to zero
3.7. SpiritLdCtrl_SetPrms ()
Syntax
int SpiritLdCtrl_SetPrms(
TSpiritLdCtrl *ld,
const TSpiritLdCtrl_Prms *prms
);
Parameters
ld Pointer to initialized persistent memory buffer.
prms Initialization parameters.
Return value
Error code.
Remarks
This function can be invoked in run-time. It is recommended to receive current parameters first and then
setup new. The proper call sequence is the following:
TSpiritLdCtrl_Prms prms;
3.8. SpiritLdCtrl_GetPrms ()
Syntax
int SpiritLdCtrl_GetPrms (
const TSpiritLdCtrl *ld,
TSpiritLdCtrl_Prms *prms
);
Parameters
ld Pointer to initialized persistent memory buffer.
prms Loudness control parameters storage.
Return value
Error code.
Remarks
This function returns actual loudness control parameters.
3.9. SpiritLdCtrl_Apply ()
Syntax
int SpiritLdCtrl_Apply (
TSpiritLdCtrl *ld,
int nChannels,
short *pcm,
int nSamplesPerCh,
void *scratch,
);
Parameters
ld Pointer to initialized persistent memory buffer.
nChannels Channel number in range [1, SPIRIT_LDCTRL_MAX_CH].
pcm Input/output PCM buffer.
nSamplesPerCh Number of input frame samples per channel.
scratch Pointer to scratch memory buffer.
Return value
Error code.
Remarks
This function applies shelving filter to input PCM data based on initialization parameters.
Note, input gain only defines particular low-pass filter, but not applied to a signal. Gain transition (filter
switching) performed softly. Full transition executed with a speed of 40dB/sec. For example, gain change
from 0 db to 20 dB (gain x1 to x10) would take .5 second. The software requires two times more
computational power during gain transition period because of two filters operate simultaneously.
#include <stdio.h>
#include "spiritLdCtrl.h"
void Process_SingleFile (
const char *szInputName,
const char *szOutputName
)
{
FILE *pFileIn = NULL, *pFileOut = NULL;
unsigned long lHz = 48000;
unsigned int nCh = 2;
// Initialize
SpiritLdCtrl_Init(ld, lHz);
// Setup parameters
{
TSpiritLdCtrl_Prms prms;
SpiritLdCtrl_GetPrms(ld, &prms);
prms.gainQ8 = 20<<8;
SpiritLdCtrl_SetPrms(ld, &prms);
}
while(1) {
if(nSamplesPerCh == 0) {
break;
}
fclose(pFileIn);
fclose(pFileOut);
}