Copying .mp3-file on SD-Card

Go To Last Post
7 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello

I duplicated a song called "test.mp3" on the SD-Card with this code, using Chans FatFS-Tiny:

WORD br, bw;         // File R/W count 
   	int Index=1;
	char file[]="test.mp3";
	char filetype[]=".mp3";
	char prefix[]="Song";
	char filename[100]={};


    // Open source file on the drive 1
    res = f_open(&fsrc, file, FA_OPEN_EXISTING | FA_READ);
		
	
		// Create destination file on the drive 0
    	res = f_open(&fdst, filename, FA_CREATE_ALWAYS | FA_WRITE);
    	if (res) LED_EVENT3(LED2,4);

	    // Copy source to destination
	    for (;;) {


	        res = f_write(&fdst, buffer, br, &bw);
 	       if (res || bw < br) break;   // error or disk full
			res = f_read(&fsrc, buffer, sizeof(buffer), &br);
			if (res || br == 0) break;   // error or eof

	    }
    // Close open files
    f_close(&fsrc);
    f_close(&fdst);


Attention: The Forum software is too dumb to display this as code:
This line is inserted before the second file is opened.

The problem now is: the new mp3, when i play it, has no id-Tag and no length information.
Another strange thing: in winamp the used bitrate is shown while playing. The test.mp3 has a constant bitrate of 320 kbit/s. While playing the copied file though, the rate slowly increased from 290 or so. I just could watch it. It grew from 290 to 300 in 15 seconds or so.

The buffer size, i used for the code is 800.

Last Edited: Sat. Nov 21, 2009 - 12:42 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
sprintf(filename,,prefix,Index,filetype);

??? The forum software can't handle the " % s % d % s " that has to be between the two commas. Spaces have to be removed.
What a crazy shit?! Do you have an explanation for this?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
Do you have an explanation for this?

Yep, idiots spamming forums with macro garbage etc. so the % anything_next_to_it_but_space has been zapped. It's a known thing around here.

John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I know nothing. But it looks like you have read/write sequence reversed which probably screws up the first write where the header info is kept.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ha, you're damn right!
I cut a part of it and then repasted it. Unfortunately at the wrong position.
tststs... :)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ok, another problem:
I have this for-loop, that shall create 4 files.

But after the first. The read-and-write loop is immediately ended by the if-Conditions:

for (;;) {

				res = f_read(&fsrc, buffer, sizeof(buffer), &br);
				if (res || br == 0) break;   // error or eof
		        res = f_write(&fdst, buffer, br, &bw);
	 	       if (res || bw < br) break;   // error or disk full

		    }

What is the source of the problem? Copying for one time works brilliantly, but what about the following?
Do i have to empty the buffer or sth?
Please give me a hint. Thank you

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You need to rewind the file pointer to the beginning of the source file. Try f_seek()