[202] | 1 | //file.c: |
---|
| 2 | |
---|
[690] | 3 | /* |
---|
[5381] | 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2012 |
---|
[690] | 5 | * |
---|
| 6 | * This file is part of libroar a part of RoarAudio, |
---|
| 7 | * a cross-platform sound system for both, home and professional use. |
---|
| 8 | * See README for details. |
---|
| 9 | * |
---|
| 10 | * This file is free software; you can redistribute it and/or modify |
---|
| 11 | * it under the terms of the GNU General Public License version 3 |
---|
| 12 | * as published by the Free Software Foundation. |
---|
| 13 | * |
---|
| 14 | * libroar is distributed in the hope that it will be useful, |
---|
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 17 | * GNU General Public License for more details. |
---|
| 18 | * |
---|
| 19 | * You should have received a copy of the GNU General Public License |
---|
| 20 | * along with this software; see the file COPYING. If not, write to |
---|
[3517] | 21 | * the Free Software Foundation, 51 Franklin Street, Fifth Floor, |
---|
| 22 | * Boston, MA 02110-1301, USA. |
---|
[690] | 23 | * |
---|
| 24 | * NOTE for everyone want's to change something and send patches: |
---|
| 25 | * read README and HACKING! There a addition information on |
---|
| 26 | * the license of this document you need to read before you send |
---|
| 27 | * any patches. |
---|
| 28 | * |
---|
| 29 | * NOTE for uses of non-GPL (LGPL,...) software using libesd, libartsc |
---|
| 30 | * or libpulse*: |
---|
| 31 | * The libs libroaresd, libroararts and libroarpulse link this lib |
---|
| 32 | * and are therefore GPL. Because of this it may be illigal to use |
---|
| 33 | * them with any software that uses libesd, libartsc or libpulse*. |
---|
| 34 | */ |
---|
| 35 | |
---|
[202] | 36 | #include "libroar.h" |
---|
| 37 | |
---|
[5224] | 38 | int roar_file_codecdetect(const char * buf, const int len) { |
---|
[215] | 39 | int codec = -1; |
---|
| 40 | |
---|
| 41 | if ( len > 3 ) { |
---|
| 42 | if ( strncmp(buf, "OggS", 4) == 0 ) { |
---|
| 43 | codec = ROAR_CODEC_OGG_GENERAL; |
---|
[1000] | 44 | if ( len > 32 ) { // this is 5 bytes after the end of the header |
---|
| 45 | if ( strncmp(buf+28, "\177FLAC", 5) == 0 ) { |
---|
| 46 | codec = ROAR_CODEC_OGG_FLAC; |
---|
| 47 | } else if ( strncmp(buf+28, "Speex", 5) == 0 ) { |
---|
| 48 | codec = ROAR_CODEC_OGG_SPEEX; |
---|
| 49 | } else if ( len > 34 ) { // this is 7 bytes after the end of the header |
---|
| 50 | if ( strncmp(buf+28, "\001vorbis", 7) == 0 ) |
---|
| 51 | codec = ROAR_CODEC_OGG_VORBIS; |
---|
| 52 | } |
---|
[215] | 53 | } |
---|
[558] | 54 | } else if ( strncmp(buf, "MThd", 4) == 0 ) { |
---|
| 55 | codec = ROAR_CODEC_MIDI_FILE; |
---|
[563] | 56 | } else if ( strncmp(buf, "RIFF", 4) == 0 ) { |
---|
| 57 | if ( len > 15 ) { |
---|
| 58 | if ( strncmp(buf+8, "WAVEfmt ", 8) == 0 ) |
---|
| 59 | codec = ROAR_CODEC_RIFF_WAVE; |
---|
| 60 | } |
---|
[623] | 61 | } else if ( strncmp(buf, "Roar", 4) == 0 ) { |
---|
| 62 | if ( len > ROAR_SPEEX_MAGIC_LEN ) { |
---|
| 63 | if ( strncmp(buf, ROAR_SPEEX_MAGIC, ROAR_SPEEX_MAGIC_LEN) == 0 ) |
---|
| 64 | codec = ROAR_CODEC_ROAR_SPEEX; |
---|
[636] | 65 | #if ROAR_SPEEX_MAGIC_LEN < ROAR_CELT_MAGIC_LEN |
---|
| 66 | } |
---|
| 67 | if ( len > ROAR_CELT_MAGIC_LEN ) { |
---|
| 68 | #endif |
---|
[4159] | 69 | if ( strncmp(buf, ROAR_CELT_MAGIC_0, ROAR_CELT_MAGIC_LEN) == 0 || |
---|
| 70 | strncmp(buf, ROAR_CELT_MAGIC_1, ROAR_CELT_MAGIC_LEN) == 0 ) |
---|
[636] | 71 | codec = ROAR_CODEC_ROAR_CELT; |
---|
[623] | 72 | } |
---|
[1196] | 73 | } else if ( strncmp(buf, "fLaC", 4) == 0 ) { |
---|
| 74 | codec = ROAR_CODEC_FLAC; |
---|
[4159] | 75 | } else if ( strncmp(buf, ".snd", 4) == 0 ) { |
---|
| 76 | codec = ROAR_CODEC_AU; |
---|
[1196] | 77 | } else if ( len > 7 && strncmp(buf, "RAUM-CF0", 8) == 0 ) { |
---|
[889] | 78 | codec = ROAR_CODEC_RAUM; |
---|
[215] | 79 | } |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | return codec; |
---|
| 83 | } |
---|
| 84 | |
---|
[5271] | 85 | const char * roar_cdromdevice (void) { |
---|
| 86 | const char * k; |
---|
[805] | 87 | |
---|
[5754] | 88 | if ( (k = roar_env_get("CDDA_DEVICE")) != NULL ) |
---|
[805] | 89 | return k; |
---|
| 90 | |
---|
| 91 | #ifdef ROAR_DEFAULT_CDROM |
---|
| 92 | return ROAR_DEFAULT_CDROM; |
---|
| 93 | #endif |
---|
| 94 | |
---|
[5148] | 95 | roar_err_set(ROAR_ERROR_NODEV); |
---|
[805] | 96 | return NULL; |
---|
| 97 | } |
---|
| 98 | |
---|
[202] | 99 | //ll |
---|