The APChannel Class


Overview

This class is used by players when they play sound. The players do not access the audio hardware, or the operating system's audio hardware interface, direcly. Instead they tell APlayer what to play. APlayer mix the channels if needed in order to play the sound. The player is able to play the sound by two different methods. With the first method, the player functions as a sample player. That is, the player just set up one sound buffer for the sample, the volume, and the panning. APlayer will then play the data in the sound buffer as a raw data stream. With the second method, the player functions as a module player, like e.g. the ProTracker player. It tells when a note has to be played, and which volume, panning, frequency etc. to use.

APlayer will allocate an APChannel object for each channel that the player uses, e.g. 4 channels. The pointers to these objects are stored in an pointer array, which the player access via the virtChannels member variable in the APAddOnPlayer class. To change the second channel, the player simply have to take the second pointer in the array and call the necessary functions via this pointer.


APChannel

Derived from: None

Declared in: APChannel.h


APChannel Constructor and Destructor


APChannel()

          APChannel(void);

The constructor initializes the class variables.


~APChannel()

          virtual ~APChannel(void);

Does nothing.


APChannel Member Functions


IsActive()

          bool IsActive(void);

This function is useful to find out, the channel is still in use - that is, it still plays a sample. It returns true if it still plays a sample, else it returns false.


Mute()

          void Mute(void);

This kills the sample being played by the channel, if any.


PlaySample()

          void PlaySample(const void *adr, uint32 startOffset, uint32 length, uint8 bit = 8);

When you want to trigger a new sample in the channel, this function can be used. The arguments are: a pointer to the sample in memory, how many samples from the beginning of the sample where to start playing, the length of the sample measured in samples, and the bit size of each sample, where 8-bit is the default. Currently only 8-bit and 16-bit are supported. If you want the sample to loop, the SetLoop() member function must be called after this function.


SetAmigaPeriod()

          void SetAmigaPeriod(uint32 period);

This is almost the same as the SetFrequency() member function, except that you give an Amiga period as parameter value instead of a frequency value.


SetBuffer()

          void SetBuffer(const void *adr, uint32 length);

This function is only used with sample players. You set which buffer to play, and the length of this buffer. Then it is up to APlayer to make sure that the buffer will be played. The arguments are: a pointer to the sample, and the length of the buffer in samples (not bytes).


SetFrequency()

          void SetFrequency(uint32 freq);

This function changes the frequency of the played sample. A call to this function will NOT re-trig the sample (start to play it from the beginning). This means that it is safe to call this function when using vibrato or portamento. The argument is the frequency you want to play with.


SetLoop()

          void SetLoop(uint32 startOffset, uint32 length, AP_LoopType type = APLOOP_Normal);

          void SetLoop(const void *adr, uint32 startOffset, uint32 length, AP_LoopType = APLOOP_Normal);

This function is called, when you want the sample to loop. There are two different methods to set the loop on the sample: normal and ping-pong.

The normal loop start playing the sample at the offset, you give as parameter, and then play "length" number of samples. When the end of the sample is reached, the sample will be repeated by restarting it from the beginning. This is done repeatingly.

The ping-pong loop plays the sample backwards "length" number of samples until it reaches the start offset. Then it plays the sample forward "length" number of samples, and then backwards. This is done repeatingly.

There are two different ways of calling this function. The first one is used for looping the same sample as with the one trigged with the PlaySample() function. Here, the arguments are: the start offset in samples, the number of samples, and the type of loop, where normal is default.

The second way is used if you want to loop into another sample, when the triggered sample has been played. This is useful when there is a lot of small samples, and you want to play them after each other. E.g. the Future Composer player use this method. The arguments to this call are: the address to the sample, the number of samples, and the type of the loop, where normal is default.


SetPanning()

          void SetPanning(uint16 pan);

This function changes the panning of the channel. The range of the argument is from 0 (APPAN_LEFT) to 256 (APPAN_RIGHT). 128 (APPAN_CENTER) is right in the middle. If you want a sample to be played in the back-speakers using a Prologic Surround Receiver, then set the panning to APPAN_SURROUND.


SetVolume()

          void SetVolume(uint32 vol);

To be able to hear any sound comming from the channel, the volume of the channel will have to be set. This is achieved by this function. The argument is the volume of the channel. The range is from 0 (mute) to 256 (full power).


The APlayer developer documentation for APlayer 3.5.2.
This documentation was written by Thomas Neumann and Flemming N. Larsen.
© Copyright 1998-2000 by The APlayer-Team / PolyCode.