How to control the AVB media steam volume size

Technical questions regarding the XTC tools and programming with XMOS.
oyhp052
Member++
Posts: 16
Joined: Fri Jun 01, 2012 7:01 am

How to control the AVB media steam volume size

Post by oyhp052 »

Code: Select all

  File path: sw_avb/module_avb_audio/src/media_fifos/media_output_fifo.h

struct media_output_fifo_data_t {
  int zero_flag;	   //!< When set, the FIFO will output zero samples instead of its contents
  unsigned int dptr;	//!< The read pointer
  unsigned int wrptr;	//!< The write pointer
  unsigned int marker;  //!< This indicates which sample is the one which the timestamps 
 // apply to
  int local_ts;	//!< When a marked sample has played out, this contains the ref clock when 
//it happened.
  int ptp_ts;	//!< Contains the PTP timestamp of the marked sample.
  unsigned int sample_count;	//!< The count of samples that have passed through the buffer.
  unsigned int zero_marker;	//!<
  ofifo_state_t state;		//!< State of the FIFO
  int last_notification_time;	//!< Last time that the clock recovery thread was informed 
//of the timestamp info
  int media_clock;		//!<
  int pending_init_notification;	//!<
  int volume;                      //!< The linear volume multipler in 2.30 signed fixed point format 
//what is the 2.30 signed fixed point format ??? 
//And how to control the AVB media steam volume size ???
  unsigned int fifo[MEDIA_OUTPUT_FIFO_WORD_SIZE];
};


norman
Active Member
Posts: 55
Joined: Wed Jan 11, 2012 2:27 pm

Post by norman »

if you work on the low cost avb audio endpoint, we maybe going to help each other. I've done some modifications to test the volume with the remote button (unused for now) :

in xr_avb_demo.xc

void ptp_server_and_gpio
uncomment

Code: Select all

c <: REMOTE_SEL; 
void demo(...)
add in the beginning

Code: Select all

int volumes[4];

	for(int i=0;i<4;i++)
	{
		volumes[i]=0x40000000;
	}
add after

Code: Select all

case c_gpio_ctl :> int cmd:
			{
				switch (cmd)
				{

Code: Select all

case REMOTE_SEL:
					{
						int vol = 0;

						if (volumes[0]==0x40000000)
						{
							vol = 0x7FFFFFFF;
						}
						else if (volumes[0]==0x7FFFFFFF)
						{
							vol = 0;
						}
						else
						{
							vol = 0x40000000;
						}

						for(int i=0;i<4;i++)
						{
							volumes[i] = vol;
						}

						set_avb_source_volumes(0, volumes, 4);
					}
					break;
in media_output_fifo.c
after

Code: Select all

#define MAX_VOLUME
add

Code: Select all

#define MEDIA_OUTPUT_FIFO_VOLUME_CONTROL
norman
Active Member
Posts: 55
Joined: Wed Jan 11, 2012 2:27 pm

Post by norman »

then search for "volume" in the all folders to see the action.

the fixed point format is as wikipedia : "Qm.f: The unambiguous form of the "Q" notation. Since the entire word is a 2's complement integer, a sign bit is implied. For example, Q1.30 describes a number with 1 integer bit and 30 fractional bits stored as a 32-bit 2's complement integer."
oyhp052
Member++
Posts: 16
Joined: Fri Jun 01, 2012 7:01 am

Post by oyhp052 »

norman wrote:then search for "volume" in the all folders to see the action.

the fixed point format is as wikipedia : "Qm.f: The unambiguous form of the "Q" notation. Since the entire word is a 2's complement integer, a sign bit is implied. For example, Q1.30 describes a number with 1 integer bit and 30 fractional bits stored as a 32-bit 2's complement integer."
Hi,
Thanks for your reply. I have tryed to use the function "media_output_fifo_set_volume(ofifos,vol) ;" in my program , in order to adjust the media volume size , but I have tryed many times and always invalid. Could you tell me that if this function is useful for audio output volume size ?
Thank you .

Yours,
Tony
norman
Active Member
Posts: 55
Joined: Wed Jan 11, 2012 2:27 pm

Post by norman »

first i've tried the same function with not good result. i think the avb reference software is very very hierarchical (obviously for good reasons) and function are very dependent and chained. use "adjust_stream" instead placed in a "switch... case" of "avb_1722_listener" call by "set_avb_source_volumes" (see what i mean...)
oyhp052
Member++
Posts: 16
Joined: Fri Jun 01, 2012 7:01 am

Post by oyhp052 »

norman wrote:if you work on the low cost avb audio endpoint, we maybe going to help each other. I've done some modifications to test the volume with the remote button (unused for now) :

in xr_avb_demo.xc

void ptp_server_and_gpio
uncomment

Code: Select all

c <: REMOTE_SEL; 
void demo(...)
add in the beginning

Code: Select all

int volumes[4];

	for(int i=0;i<4;i++)
	{
		volumes[i]=0x40000000;
	}
add after

Code: Select all

case c_gpio_ctl :> int cmd:
			{
				switch (cmd)
				{

Code: Select all

case REMOTE_SEL:
					{
						int vol = 0;

						if (volumes[0]==0x40000000)
						{
							vol = 0x7FFFFFFF;
						}
						else if (volumes[0]==0x7FFFFFFF)
						{
							vol = 0;
						}
						else
						{
							vol = 0x40000000;
						}

						for(int i=0;i<4;i++)
						{
							volumes[i] = vol;
						}

						set_avb_source_volumes(0, volumes, 4);
					}
					break;
in media_output_fifo.c
after

Code: Select all

#define MAX_VOLUME
add

Code: Select all

#define MEDIA_OUTPUT_FIFO_VOLUME_CONTROL
Hi, norman. Thanks for your suggestion . I've modifyed my sw_avb files as follow the steps your provide, but when I compile the project it report compile errors (see the Fig).
So, I can not be sure if this method is valid to adjust the media output volume size .
You do not have the required permissions to view the files attached to this post.
oyhp052
Member++
Posts: 16
Joined: Fri Jun 01, 2012 7:01 am

Post by oyhp052 »

A valid way to adjust the audio output volume size ( but it's not a good way):
norman , At present, my project which used this method to adjust the output volume level.

in media_output_fifo_support.xc

void ofifos_sample(
streaming chanend samples_out,
media_output_fifo_t output_fifos[],
int num_channels,
char vol[8] //add variable char vol[8]
)

sample = media_output_fifo_pull_sample(output_fifos,timestamp);
sample = sample*vol ; // add in here , i=1,2,3...8, vol=0,1,2...10.
samples_out <: sample;


if vol=0, then output volume is mutu.
if vol=1, then output volume is on.
if vol=2,3...10, then ouput volume is increased. But the output audio may be distortion.

Could you have a better way ,please ?
norman
Active Member
Posts: 55
Joined: Wed Jan 11, 2012 2:27 pm

Post by norman »

oyhp052 wrote:when I compile the project it report compile errors (see the Fig)
i believe you have #define MEDIA_OUTPUT_FIFO_VOLUME_CONTROL (?)
maybe you also have to include in project reference (right clic on the project \ properties ) the module avb, not sure.
oyhp052
Member++
Posts: 16
Joined: Fri Jun 01, 2012 7:01 am

Post by oyhp052 »

norman wrote:
oyhp052 wrote:when I compile the project it report compile errors (see the Fig)
i believe you have #define MEDIA_OUTPUT_FIFO_VOLUME_CONTROL (?)
maybe you also have to include in project reference (right clic on the project \ properties ) the module avb, not sure.
Yes, I have #define MEDIA_OUTPUT_FIFO_VOLUME_CONTROL in media_output_fifo.c .
And #include avb.h in xr_avb_demo.xc . I'm sure . But when compile project it display error.
Maybe I should try more times .
And do you have try my way of the volume control on above ?
norman
Active Member
Posts: 55
Joined: Wed Jan 11, 2012 2:27 pm

Post by norman »

sorry, i'm quit busy, i think i will not have time to try right now... i'm still working on the card, if i found a better way, i'll keep you informed.