The function mmap(....) appears several times in madplay.c and minimad.c
.I don't know what the function will exactly do ,bu I think it's related with paging ?
The function maps the file into the memory address space of the process. The file can then be accessed directly with memory references rather than by calling read(). This is helpful because it enables random access without worries about buffering, as this is done in the kernel -- the file is paged into memory only as needed. It also eliminates copying data from the kernel's buffer into user space.
But I want to port mad to a simple system so there is no such complex function call available.My question is how can I write someting to replace mmap function call.
I don't know if Windows provides a similar capability. However, `madplay' has been written to work without it. Just don't define HAVE_MMAP.
Can I just allocate a mem buffer and read the file to the buffer and using the pointer to buffer as void * fdm in the main()? I try it but it seems to cause some error.When I decode to the almost end of a mp3 file ,it will sometimes report 0x0101 error.
/* fdm = mmap(0, stat.st_size, PROT_READ, MAP_SHARED, STDIN_FILENO, 0);*/ fdm = malloc(stat.st_size); inputstream = fdopen(STDIN_FILENO,"r"); fread(fdm,sizeof(char),stat.st_size,inputstream);
This will probably work, although it is perhaps a bit greedy to read the entire file into memory at once. You might prefer to read the file in chunks, as `madplay' will do when HAVE_MMAP is not defined.
The 0x0101 error means MAD lost synchronization with the bitstream. I have found this to be common if the file contains an ID3v1 tag at the end of the file; the tag is apparently not always located at a frame boundary. I will try to work around this, but for now you can ignore the error.