1 /*******************************************************************************
2  * Copyright 2009-2016 Jörg Müller
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  ******************************************************************************/
16 
17 #pragma once
18 
19 /**
20  * @file FileWriter.h
21  * @ingroup file
22  * The FileWriter class.
23  */
24 
25 #include "respec/Specification.h"
26 #include "file/IWriter.h"
27 
28 #include <string>
29 #include <vector>
30 #include <memory>
31 
32 AUD_NAMESPACE_BEGIN
33 
34 class IReader;
35 
36 /**
37  * The FileWriter class is able to create IWriter classes as well as write readers to them.
38  */
39 class AUD_API FileWriter
40 {
41 private:
42 	// hide default constructor, copy constructor and operator=
43 	FileWriter() = delete;
44 	FileWriter(const FileWriter&) = delete;
45 	FileWriter& operator=(const FileWriter&) = delete;
46 
47 public:
48 	/**
49 	 * Creates a new IWriter.
50 	 * \param filename The file to write to.
51 	 * \param specs The file's audio specification.
52 	 * \param format The file's container format.
53 	 * \param codec The codec used for encoding the audio data.
54 	 * \param bitrate The bitrate for encoding.
55 	 * \return The writer to write data to.
56 	 */
57 	static std::shared_ptr<IWriter> createWriter(std::string filename, DeviceSpecs specs, Container format, Codec codec, unsigned int bitrate);
58 
59 	/**
60 	 * Writes a reader to a writer.
61 	 * \param reader The reader to read from.
62 	 * \param writer The writer to write to.
63 	 * \param length How many samples should be transferred.
64 	 * \param buffersize How many samples should be transferred at once.
65 	 */
66 	static void writeReader(std::shared_ptr<IReader> reader, std::shared_ptr<IWriter> writer, unsigned int length, unsigned int buffersize, void(*callback)(float, void*) = nullptr, void* data = nullptr);
67 
68 	/**
69 	 * Writes a reader to several writers.
70 	 * \param reader The reader to read from.
71 	 * \param writers The writers to write to.
72 	 * \param length How many samples should be transferred.
73 	 * \param buffersize How many samples should be transferred at once.
74 	 */
75 	static void writeReader(std::shared_ptr<IReader> reader, std::vector<std::shared_ptr<IWriter> >& writers, unsigned int length, unsigned int buffersize, void(*callback)(float, void*) = nullptr, void* data = nullptr);
76 };
77 
78 AUD_NAMESPACE_END
79