/** * Creates a WaveData container from the specified url * * @param path URL to file * @return WaveData containing data, or null if a failure occured */ public static WaveData create(String path) { try { // due to an issue with AudioSystem.getAudioInputStream // and mixing unsigned and signed code // we will use the reader directly WaveFileReader wfr = new WaveFileReader(); InputStream is = WaveData.class.getResourceAsStream(path); if (is == null) throw new IOException("File not found: " + path); return create(wfr.getAudioInputStream(new BufferedInputStream(is))); } catch (Exception e) { //System.err.println("Unable to create from: " + path + ", " + e.getMessage()); e.printStackTrace(); return null; } }
/** * Creates a WaveData container from the specified url * * @param path URL to file * @return WaveData containing data, or null if a failure occured */ public static WaveData create(URL path) { try { // due to an issue with AudioSystem.getAudioInputStream // and mixing unsigned and signed code // we will use the reader directly //System.out.println("Path! :D : " + path); WaveFileReader wfr = new WaveFileReader(); return create(wfr.getAudioInputStream(new BufferedInputStream(path.openStream()))); } catch (Exception e) { System.out.println("Unable to create from: " + path + ", " + e.getMessage()); return null; } }
/** * Creates a WaveData container from the specified url * * @param path URL to file * @return WaveData containing data, or null if a failure occured */ public static WaveData create(URL path) { try { // due to an issue with AudioSystem.getAudioInputStream // and mixing unsigned and signed code // we will use the reader directly WaveFileReader wfr = new WaveFileReader(); return create(wfr.getAudioInputStream(new BufferedInputStream(path.openStream()))); } catch (Exception e) { logger.error("Unable to create from: " + path + ", " + e.getMessage()); return null; } }
/** * Creates a WaveData container from the specified url * * @param path URL to file * @return WaveData containing data, or null if a failure occured */ public static WaveData create(URL path) { try { // due to an issue with AudioSystem.getAudioInputStream // and mixing unsigned and signed code // we will use the reader directly WaveFileReader wfr = new WaveFileReader(); return create(wfr.getAudioInputStream(new BufferedInputStream(path.openStream()))); } catch (Exception e) { org.lwjgl.LWJGLUtil.log("Unable to create from: " + path + ", " + e.getMessage()); return null; } }
/** * Creates a WaveData container from the specified url * * @param path URL to file * @return WaveData containing data, or null if a failure occured */ public static WaveData create(URL path) { try { // due to an issue with AudioSystem.getAudioInputStream // and mixing unsigned and signed code // we will use the reader directly WaveFileReader wfr = new WaveFileReader(); return create(wfr.getAudioInputStream(new BufferedInputStream(path.openStream()))); } catch (Exception e) { print("Unable to create from: " + path + ", " + e.getMessage()); return null; } }
/** * Creates a WaveData container from the specified url * * @param path URL to file * @return WaveData containing data, or null if a failure occurred */ public static WaveData create(URL path) throws DwarfException { try { // due to an issue with AudioSystem.getAudioInputStream // and mixing unsigned and signed code // we will use the reader directly return create(new WaveFileReader().getAudioInputStream(new BufferedInputStream(path.openStream()))); } catch (IOException | UnsupportedAudioFileException ex) { throw new DwarfException(ex); } }
@Override public IAudioInfo decode(InputStream strIn) throws IOException { WaveFileReader reader = new WaveFileReader(); try (AudioInputStream ais = reader.getAudioInputStream(strIn)) { AudioFormat fmt = ais.getFormat(); int chanFmt = -1; switch (fmt.getChannels()) { case 1: switch (fmt.getSampleSizeInBits()) { case 8: chanFmt = AL10.AL_FORMAT_MONO8; break; case 16: chanFmt = AL10.AL_FORMAT_MONO16; break; } break; case 2: switch (fmt.getSampleSizeInBits()) { case 8: chanFmt = AL10.AL_FORMAT_STEREO8; break; case 16: chanFmt = AL10.AL_FORMAT_STEREO16; break; } break; } if (chanFmt == -1) throw new UnsupportedAudioFileException("Illegal audio format!"); byte[] data = new byte[ais.available()]; int read = 0, total = 0; while ((read = ais.read(data, total, data.length - total)) != 1 && total < data.length) total += read; return new WavData(data, chanFmt, (int)fmt.getSampleRate(), fmt.getSampleSizeInBits() == 16, fmt.isBigEndian()); } catch (UnsupportedAudioFileException e) { throw new IOException(e); } }