Commit f1e88c83 authored by ROOL's avatar ROOL :robot:
Browse files

This commit was manufactured by cvs2git to create tag 'SndSetup-1_00'.

Sprout from master 2003-02-28 16:15:27 UTC Ben Avison <bavison@gitlab.riscosopen.org> 'Given a major overhaul to work with the HAL version of the SoundControl'
Delete:
    SetVolumes/c/setvolumes
No related merge requests found
*,ffb gitlab-language=bbcbasic linguist-language=bbcbasic linguist-detectable=true *,ffb gitlab-language=bbcbasic linguist-language=bbcbasic linguist-detectable=true
c/** gitlab-language=c linguist-language=c linguist-detectable=true c/** gitlab-language=c linguist-language=c linguist-detectable=true
**/c/** gitlab-language=c linguist-language=c linguist-detectable=true
h/** gitlab-language=c linguist-language=c linguist-detectable=true h/** gitlab-language=c linguist-language=c linguist-detectable=true
/* Copyright 1998 Acorn Computers Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*---------------------------------------------------------------------------*/
/* File: c.setvolumes */
/* Purpose: App to set the volume levels on the Codec, via SoundCtrl. */
/* Volumes are stored in text file <Choices$Write>.Sound.Sound */
/* Author: Richard Leggett */
/* History: 05-Feb-98: RML: Begun. */
/*---------------------------------------------------------------------------*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "swis.h"
#define NumberOfChannels 8
#define SoundCtrl_SetVolume 0x50002
#define SoundCtrl_ChannelInfo 0x50004
#define Flag_LeftMuted 1u<<0
#define Flag_RightMuted 2u<<1
#define ChoicesFile "<Choices$Write>.Sound.Sound"
/* SndSetup numbers channels from 0 to NumberOfChannels. The toolbox ID of the slider
gadget equals this channel number. However, SoundCtrl adopts different numbering, so
the array channel_no maps between SndSetup and SoundCtrl's numbering. The array
channel_name contains the name of each channel as specified in the Sound configuration
file in <Choices$Write>.Sound. */
static char *channel_name[NumberOfChannels] = { "Master", "System", "CD", "Line",
"Mic", "Capture", "Playback", "Wavetable" };
static int channel_no[NumberOfChannels] = { 0, 11, 2, 1,
5, 8, 12, 10 };
static int min_volume[NumberOfChannels];
/*---------------------------------------------------------------------------*
* sound_set_volume *
* *
* Set the volume for a given channel. *
* *
* In: channel = channel whose volume we wish to change. This number is our *
* internal number (between 0 and 7), rather than the channel *
* number held by SoundCtrl. The channel_no array maps between *
* the two. *
* volume = volume, in db, times 10. *
*---------------------------------------------------------------------------*/
void sound_set_volume(int channel, int volume)
{
float db;
int flags;
/* If volume is minimum value, then mute instead */
if (db == min_volume[channel]) flags = Flag_LeftMuted + Flag_RightMuted;
else flags = 0;
/* Convert a volume integer (db*10 eg. -125 means -12.5db) into 32bit with 16bit fraction */
db = (1<<16) * ((float)volume) / 10;
/* Set the volume */
_swix(SoundCtrl_SetVolume, _INR(0,4), 0, channel_no[channel], 0, (int)db, (int)db);
}
/*---------------------------------------------------------------------------*
* main *
*---------------------------------------------------------------------------*/
int main(void)
{
FILE *fp;
char *item;
char *value;
char buffer[256];
int n, colon, more=1;
int min_i, max_i, step_i;
float min_f, max_f, step_f;
/* Read in min, max & volume settings for the channels */
for (n=0; n<NumberOfChannels; n++)
{
/* Read the min, max and step of the volume for this channel */
_swix(SoundCtrl_ChannelInfo, _INR(0,1)|_OUTR(4,6),
0, channel_no[n], &min_i, &max_i, &step_i);
/* Convert the values we read back (32bit, 16bit for fraction) into floats */
min_f = 10 * ((float)min_i) / (1<<16);
max_f = 10 * ((float)max_i) / (1<<16);
step_f = 10 * ((float)step_i) / (1<<16);
min_volume[n] = (int)min_f;
}
/* Now open the choices file */
fp = fopen(ChoicesFile, "r");
if (!fp) return 0;
while (more)
{
/* Get next string */
more = (int)fgets(buffer, 256, fp);
if (more)
{
/* Check for a colon in this line */
colon = strstr(buffer, ":") - buffer;
if (colon>0)
{
/* Break the string into item eg. ("Master") and value (eg. "-45") */
buffer[colon] = 0;
item = buffer;
value = item + colon + 1;
value[strlen(value)-1] = 0;
/* Is this item one of the names of channels? */
for (n=0; n<NumberOfChannels; n++)
{
if (strcmp(channel_name[n], item)==0)
{
/* The item corresponds to channel n in our array */
int v = (int) (atof(value)*10);
/* Update slider and set volume */
sound_set_volume(n, v);
}
}
}
}
}
fclose(fp);
return 0;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment